Edit Arrays and Iterators

JPHP has two useful classes for working with arrays and iterators. Our way is universal methods which can work with arrays and iterators.

Array Functions

The JPHP has own util class for working with iterators and arrays php\lib\Items, for example:

Why Items?

We cannot use Array because the all methods work with not only arrays, List because it’s a lexer keyword, Arr because it’s an ugly reduction of the Array word, Collection - it’s too long word.

use php\lib\Items;

$keys = Items::keys($array);

// instead of

$keys = array_keys($array);

Flow class

Supports not only arrays, also iterators and traversable. Flow implements Iterator.

Many methods of Flow return a new Flow instance, so you can use fluent interface to lazy manipulate arrays and iterators, for instance:

$someArray = [....]; $collection = Flow::of($someArray) ->filter(function($el) { return $el > 18; }) ->map(function($el, $key) { return "[" . $el . "]"; }); foreach ($collection as $key => $value) { var_dump($value); } // You can use a flow instance only one time as a generator // The next code will throw an exception foreach ($collection ... ) { }