Items

php\lib\Items

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 toArray($collection, $withKeys = false)

Converts $collection to array

Parameters:
  • $collectionarray, Iterator
  • $withKeysbool
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 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 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