geeksareforlife / utilities
Various general purpose utilities
Requires
- php: ^5.3.3 || ^7.0
README
This small package is simply a collection of functions that I find useful across multiple projects.
Installation
Install using Composer:
composer require geeksareforlife/utilities
The only requirement at this time is PHP 7.1 and above.
Usage
The package provides static functions grouped into classes. See the list of functions below.
When using, you can either call the functions using the fully qualified name:
$newArray = GeeksAreForLife\Utilities\Arrays::sanitiseArray($array, $keys);
or have a use statement at the top of your file:
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.
For example, given this as an input array:
$array = [
'red' => 'abc',
'green' => true,
'blue' => [1, 2, 3],
];
and the following as the list of keys:
$keys = ['red', 'blue', 'yellow'];
The returned array will be:
$array = [
'red' => 'abc',
'blue' => [1, 2, 3],
];
Notice that yellow
does not appear as a key.
Arrays::sanitiseArrayList($list, $keys)
This function takes the provided list of arrays and sanitises each one before returning a list of the sanitised arrays.
The individual arrays are santised in exactly the same way as noted in the previous function.
Strings::startsWith($string, $startsWith)
This function checks if the provided $string
starts with $startsWith
and returns either true
or false
.
$startsWith
can be of any length. An empty string in $startsWith
will return true
.
Strings::endsWith($string, $endsWith)
This function checks if the provided $string
ends with $endsWith
and returns either true
or false
$endsWith
can be of any length. An empty string in $endsWith
will return true
.
Contributing
Firstly, I am really happy that you are thinking about contributing to this project.
You can find the Contributing Guidelines in the root of this repository.
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.
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.