Skip to content

Latest commit

 

History

History
47 lines (35 loc) · 931 Bytes

arr.md

File metadata and controls

47 lines (35 loc) · 931 Bytes

Arr Helpers

Arr is a namespace of common array methods. Similar to the array_methods except with a consistent parameter order

Array methods will always accept the subject array before the rest of the parameters

Arr::map

Arr::map($array, $callback)

Maps through an array calling the callback with each item, it's index and the complete array

Example

<?
Arr::map(
  [10, 9, 8],
  function ($item, $index, $arr) {
    return $item - $index * 2;
  }
) === [20, 16, 14]
?>

Arr::split

Arr::split($array, $callback): [falsey[], truthy[]]

Filters through an array calling the callback with each item, if the callback returns true it is added to the second result array, if it's false it is added to the first result array

Example

<?
Arr::split(
  [10, 9, 8],
  function ($item, $index, $arr) {
    return !($item % 2);
  }
) === [[9], [10, 8]]
?>