Releases: minwork/array
Releases · minwork/array
Unpack refactor and improved isAssoc documentation
Unpack
- Replaced internal method argument with mode argument
- Added 4 modes of handling array at highest nesting depth
- UNPACK_ALL (default) - unpack every nested array
$arr['foo.bar.0'] = 'a'; $arr['foo.bar.1'] = 'b';
- UNPACK_PRESERVE_LIST_ARRAY - preserve list type array
$arr['foo.bar'] = ['a', 'b'];
- UNPACK_PRESERVE_ASSOC_ARRAY - preserve associative array
$arr['foo.bar'] = ['a' => 1, 'b' => 2];
- UNPACK_PRESERVE_ARRAY - work as both of options above combined
- UNPACK_ALL (default) - unpack every nested array
- For examples check out unpack test method
testUnpack
- Examples in documentation coming soon
isAssoc
- Clarified in PHPDoc how both values of
$strict
flag works
Added new method - isNested and getDepth
isNested
Check if any element of an array is also an array.
For example [1, 2, 3]
is a regular array so it isn't nested and [1, 2 => [], 3]
has another array as one of it's elements so it is nested.
getDepth
Get nesting depth of an array.
Taking example from above, [1, 2, 3]
is a regular array so it has depth of 1 and [1, 2 => [], 3]
has depth of 2 because of a second array in it. More detailed examples showing more complex cases can be found in documentation.
Added new method - intersectObjects
Calculate intersection between two or more arrays of objects using objects hashes for comparison.
Added new method - sortObjects
New method sortObjects can be used for sorting array of objects by supplying method name (possibly with method arguments) to call on every object in array
Added Unpack and improved Map method
Unpack
- Added unpack method to easily convert multidimensional arrays to flat map of keys concatenated by dot and corresponding values
Map
New functionality
- Now map method handles multidimensional arrays with ease using one of three modes
- MAP_ARRAY_KEY_VALUE - Basic mapping supplying callback with current element key as 1st argument and value as 2nd
- MAP_ARRAY_VALUE_KEYS_LIST - Multidimensional mapping supplying callback with current element value as 1st argument and element keys as subsequent arguments
- MAP_ARRAY_KEYS_ARRAY_VALUE - Multidimensional mapping supplying callback with array of current element keys as 1st argument and element value as 2nd
Arguments order depreciation
- Map method now accepts array as 1st argument and callback as 2nd issuing appropriate deprecation warning when using old syntax (callback as 1st and array as 2nd)
For use cases check out updated examples section