Utilities
, (*1)
This small package is simply a collection of functions that I find useful across multiple projects., (*2)
Installation
Install using Composer:, (*3)
composer require geeksareforlife/utilities
The only requirement at this time is PHP 7.1 and above., (*4)
Usage
The package provides static functions grouped into classes. See the list of functions below., (*5)
When using, you can either call the functions using the fully qualified name:, (*6)
$newArray = GeeksAreForLife\Utilities\Arrays::sanitiseArray($array, $keys);
or have a use statement at the top of your file:, (*7)
use GeeksAreForLife\Utilities\Arrays;
...
$newArray = Arrays::sanitiseArray($array, $keys);
Arrays::sanitiseArray($array, $keys)
This function takes two arguments - the array you want to sanitise and a list of keys you want
in the returned array., (*8)
For example, given this as an input array:, (*9)
$array = [
'red' => 'abc',
'green' => true,
'blue' => [1, 2, 3],
];
and the following as the list of keys:, (*10)
$keys = ['red', 'blue', 'yellow'];
The returned array will be:, (*11)
$array = [
'red' => 'abc',
'blue' => [1, 2, 3],
];
Notice that yellow does not appear as a key., (*12)
Arrays::sanitiseArrayList($list, $keys)
This function takes the provided list of arrays and sanitises each one before returning a list
of the sanitised arrays., (*13)
The individual arrays are santised in exactly the same way as noted in the previous function., (*14)
Strings::startsWith($string, $startsWith)
This function checks if the provided $string starts with $startsWith and returns either true or false., (*15)
$startsWith can be of any length. An empty string in $startsWith will return true., (*16)
Strings::endsWith($string, $endsWith)
This function checks if the provided $string ends with $endsWith and returns either true or false, (*17)
$endsWith can be of any length. An empty string in $endsWith will return true., (*18)
Contributing
Firstly, I am really happy that you are thinking about contributing to this project., (*19)
You can find the Contributing Guidelines in the root of this repository., (*20)
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms., (*21)
Filing a Bug or Requesting a feature
Both of these are contributing too! You can find details on how to do both in the Contributing Guidelines., (*22)