Releases: pdscopes/php-arrays
v3.0.0
Minimum PHP increased to 7.1
v2.1.0 adds github actions to run tests and upgrades to php>=7.1 and phpunit…
Renamed function names
-
Renamed functions to sit in line with php function names:
Arr::findKey -> Arr::searchKeyArr::find -> Arr::searchArrDots::search -> ArrDots::collateCollection::find -> Collection::search
-
Added
Arr::pluckandArrDots::pluckswitch combines column and collapse
v1.3.5
v1.3.4
Arr
Arr::column Get the values from a single column in $array. An array of columns can be provided to chain call column.
Arr::collapse Merge all elements of $array into a single array.
ArrDots
ArrDots::column Get the values from a single column in $array. Dots notation can be provided to chain call column.
v1.3.3
Arrayable interface, Collection class, new functions for Arr class
Added Arrayable interface
Arrayable interface defines a simple function that should convert an instance into an array.
Added Collection class
A Collection is way to interact with an array as an object. It provides many of the methods available in Arr.
New function in Arr
Two new functions have been added to Arr:
1 Arr::filter: supply a callable and the array will be filter to only contain values that return true
2 Arr::except: the opposite of only, leaves all items in the array except those keys provided.
New method: ArrDots::search
ArrDots::search is a new method that, given a key with possible wildcards, will return an associative array of all matching dot notations to their values. For example:
$data = [
'field0' => 'field0-value',
'array0' => [1, 2, 3, 4],
'array1' => [
['item0' => 'item0-value'],
['item0' => 'item1-value'],
],
'array2' => [
['sub-array0' => [1, 2, 3, 4]],
['sub-array0' => [1, 2, 3, 4]],
],
'array3' => [
['sub-array1' => [['item1' => 'item2-value'], ['item1' => 'item3-value']]],
['sub-array1' => [['item1' => 'item4-value']]],
],
];
// Simple
$results = ArrDots::search($data, 'field0');
$results === [
'field0' => 'field0-value
];
// End with wildcard
$results = ArrDots::search($data, 'array0.*', '*');
$results === [
'array0.0' => 1,
'array0.1' => 2,
'array0.2' => 3,
'array0.3' => 4,
];
// Single wildcard inside
$results = ArrDots::search($data, 'array2.*.sub-array0', '*');
$results === [
'array2.0.sub-array0' => [1, 2, 3, 4],
'array2.1.sub-array0' => [1, 2, 3, 4],
];
// Multiple wildcard
$results = ArrDots::search($data, 'array3.*.sub-array1.*.item1', '*');
$results === [
'array3.0.sub-array1.0.item1' => 'item2-value',
'array3.0.sub-array1.1.item1' => 'item3-value',
'array3.1.sub-array1.0.item1' => 'item4-value',
];PHP Array Helpers
This is a new library of helper functions for php arrays/ArrayAccess. We release with 3 classes Arr, ArrDots, and Dots.
Arr is full of functions for array/ArrayAccess objects.
ArrDots is full of functions for "dot notation" access of array/ArrayAccess objects.
Dots is an implementation of ArrayAccess that with functions to set the underlining array as a copy or a reference.