kamyshev / array_actions
Set of simple actions with arrays
Installs: 1 880
Dependents: 1
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 1
Open Issues: 1
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^7.0
- symplify/easy-coding-standard: ^5.1
- vimeo/psalm: ^2.0
This package is auto-updated.
Last update: 2020-01-25 14:38:36 UTC
README
Set of simple actions with arrays
Installation
To get the latest version of array_actions
, simply require the project using Composer:
$ composer require kamyshev/array_actions
Usage
Actions list:
array_find
To use array_find
, simply pass an array and callback:
$records = [ [ 'state' => 'IN', 'city' => 'Indianapolis', 'object' => 'School bus', ], [ 'state' => 'IN', 'city' => 'Indianapolis', 'object' => 'Manhole', ], [ 'state' => 'IN', 'city' => 'Plainfield', 'object' => 'Basketball', ], [ 'state' => 'CA', 'city' => 'San Diego', 'object' => 'Light bulb', ], [ 'state' => 'CA', 'city' => 'Mountain View', 'object' => 'Space pen', ], ]; $found = array_find($records, function ($state) { return $state['city'] === 'San Diego'; });
Example output:
Array
(
[state] => CA
[city] => San Diego
[object] => Light bulb
)
If the element was not found, array_find
returns null
.
array_head
To use array_find
, simply pass an array and callback:
$records = [ [ 'state' => 'IN', 'city' => 'Indianapolis', 'object' => 'School bus', ], [ 'state' => 'IN', 'city' => 'Indianapolis', 'object' => 'Manhole', ], [ 'state' => 'IN', 'city' => 'Plainfield', 'object' => 'Basketball', ], [ 'state' => 'CA', 'city' => 'San Diego', 'object' => 'Light bulb', ], [ 'state' => 'CA', 'city' => 'Mountain View', 'object' => 'Space pen', ], ]; $head = array_head($records);
Example output:
Array
(
[state] => IN
[city] => Indianapolis
[object] => School bus
)
If the array is empty, array_head
returns null
.