arr

php\lib\arr

Library for working with collections - arrays, iterators, etc.

Methods


__construct()

private

static count($collection)

Returns element count of the collection

Warning

for iterators it will iterate all elements to return the result

Parameters:
  • $collectionarray, Countable, Iterator
Returns:

int element count

static has($collection, $value, $strict = false)
Parameters:
  • $collectionarray, Traversable
  • $valuemixed
  • $strictbool
Returns:

bool

static toArray($collection, $withKeys = false)

Converts $collection to array

Parameters:
  • $collectionarray, Iterator
  • $withKeysbool
Returns:

array

static of($collection, $withKeys = false)

Alias of toArray()

Parameters:
  • $collectionarray, Iterator
  • $withKeysbool, php\lib\false
Returns:

array

static toList($collection)

Example: items::toList([‘x’ => 10, 20], 30, [‘x’ => 50, 60]) -> [10, 20, 30, 50, 60]

Parameters:
  • $collection
Returns:

array

static keys($collection)

Returns all keys of collection

Parameters:
  • $collectionarray, Iterator
Returns:

array

static combine($keys, $values)

Combines two collections to array.

Parameters:
  • $keysarray, Iterator
  • $valuesarray, Iterator
Returns:

array, null returns null if size of arrays is not equals.

static map($collection, $callback)
Parameters:
  • $collectionarray, Iterator
  • $callbackcallable
static flatten($collection, $maxLevel = -1)

Returns a new array that is a one-dimensional flattening of this collection (recursively). That is, for every element that is an collection, extract its elements into the new array. If the optional $maxLevel argument > -1 the level of recursion to flatten.

Parameters:
  • $collectionarray, Iterator
  • $maxLevelint
Returns:

array

static sort($collection, $comparator = null, $saveKeys = false)

Sorts the specified list into ascending order

Parameters:
  • $collectionarray, Iterator
  • $comparatorcallable - ($o1, $o2) -> int where -1 smaller, 0 equal, 1 greater
  • $saveKeysbool
Returns:

array

static sortByKeys($collection, $comparator = null, $saveKeys = false)

Sorts the specified list into ascending order by keys

Parameters:
  • $collectionarray, Iterator
  • $comparatorcallable - ($key1, $key2)
  • $saveKeysbool
Returns:

array

static peak($array)

Returns the last element of array.

Parameters:
  • $array
Returns:

mixed last value of array

static push($array, $values)
Parameters:
  • $arrayarray, ArrayAccess
  • $values
static pop($array)
Parameters:
  • $arrayarray
Returns:

mixed

static shift($array)
Parameters:
  • $arrayarray
Returns:

mixed

static unshift($array, $values)
Parameters:
  • $arrayarray
  • $values
static first($collection)
Parameters:
  • $collectionTraversable, array
Returns:

mixed

static firstKey($collection)
Parameters:
  • $collectionTraversable, array
Returns:

string, int, null

static reverse($array)
Parameters:
  • $arrayarray
Returns:

array