PHP Class Jyxo\Spl\ArrayUtil

Author: Jakub Tománek
Datei anzeigen Open project: jyxo/php

Public Methods

Method Description
keymap ( Traversable $traversable, Closure $key, Closure $value = null ) : array Creates an associative array from iterator which doesn't return proper keys.
range ( mixed $low, mixed $high, Closure $step, Closure $compare = null ) : array Creates an array containing item range. Similar to range() but with closures.

Method Details

keymap() public static method

Keys are generated by applying callback $key to the current value. It is also possible to apply another callback directly to the value. Key callback is called BEFORE value callback. Example: $data = \Jyxo\Spl\ArrayUtil::keymap($iterator, function(Object $object) { return $object->getId(); });
public static keymap ( Traversable $traversable, Closure $key, Closure $value = null ) : array
$traversable Traversable Iterator
$key Closure Closure for generating keys
$value Closure Closure for modifying data (Optional)
return array

range() public static method

Params $low and $high are inclusive. If $low > $high, resulting array will be in descending order.
public static range ( mixed $low, mixed $high, Closure $step, Closure $compare = null ) : array
$low mixed Minimal value
$high mixed Maximal value
$step Closure Closure which creates next value from current
$compare Closure comparing closure for detecting if we're at the end of the range (Optional)
return array