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:
- $collection – array, Countable, Iterator
Returns: int element count
- static
has
($collection, $value, $strict = false)¶
Parameters:
- $collection – array, Traversable
- $value – mixed
- $strict – bool
Returns: bool
- static
toArray
($collection, $withKeys = false)¶Converts $collection to array
Parameters:
- $collection – array, Iterator
- $withKeys – bool
Returns: array
- static
of
($collection, $withKeys = false)¶Alias of toArray()
Parameters:
- $collection – array, Iterator
- $withKeys – bool, 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:
- $collection – array, Iterator
Returns: array
- static
combine
($keys, $values)¶Combines two collections to array.
Parameters:
- $keys – array, Iterator
- $values – array, Iterator
Returns: array, null returns null if size of arrays is not equals.
- static
map
($collection, $callback)¶
Parameters:
- $collection – array, Iterator
- $callback – callable
- 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:
- $collection – array, Iterator
- $maxLevel – int
Returns: array
- static
sort
($collection, $comparator = null, $saveKeys = false)¶Sorts the specified list into ascending order
Parameters:
- $collection – array, Iterator
- $comparator – callable - ($o1, $o2) -> int where -1 smaller, 0 equal, 1 greater
- $saveKeys – bool
Returns: array
- static
sortByKeys
($collection, $comparator = null, $saveKeys = false)¶Sorts the specified list into ascending order by keys
Parameters:
- $collection – array, Iterator
- $comparator – callable - ($key1, $key2)
- $saveKeys – bool
Returns: array
- static
peak
($array)¶Returns the last element of array.
Parameters:
- $array –
Returns: mixed last value of array
- static
push
($array, $values)¶
Parameters:
- $array – array, ArrayAccess
- $values –
- static
pop
($array)¶
Parameters:
- $array – array
Returns: mixed
- static
shift
($array)¶
Parameters:
- $array – array
Returns: mixed
- static
unshift
($array, $values)¶
Parameters:
- $array – array
- $values –
- static
first
($collection)¶
Parameters:
- $collection – Traversable, array
Returns: mixed
- static
firstKey
($collection)¶
Parameters:
- $collection – Traversable, array
Returns: string, int, null
- static
reverse
($array)¶
Parameters:
- $array – array
Returns: array