Skip to content

Releases: minwork/array

Unpack refactor and improved isAssoc documentation

29 May 21:53
Compare
Choose a tag to compare

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
  • 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

27 May 06:53
Compare
Choose a tag to compare

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

22 May 10:37
Compare
Choose a tag to compare

Calculate intersection between two or more arrays of objects using objects hashes for comparison.

Added new method - sortObjects

16 May 05:56
Compare
Choose a tag to compare

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

25 Apr 09:39
Compare
Choose a tag to compare

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