arr¶
-
php\lib\arr
Library for working with collections - arrays, iterators, etc.
Methods
__construct
()¶private
- static
count
($collection)¶Returns element count of the collection
Предупреждение
for iterators it will iterate all elements to return the result
Параметры:
- $collection –
array
,Countable
,Iterator
Результат:
int
element count
- static
has
($collection, $value, $strict = false)¶
Параметры:
- $collection –
array
,Traversable
- $value –
mixed
- $strict –
bool
Результат:
bool
- static
toArray
($collection, $withKeys = false)¶Converts $collection to array
Параметры:
- $collection –
array
,Iterator
- $withKeys –
bool
Результат:
array
- static
of
($collection, $withKeys = false)¶Alias of toArray()
Параметры:
- $collection –
array
,Iterator
- $withKeys –
bool
,php\lib\false
Результат:
array
- static
toList
($collection)¶Example: items::toList([‘x’ => 10, 20], 30, [‘x’ => 50, 60]) -> [10, 20, 30, 50, 60]
Параметры:
- $collection –
Результат:
array
- static
keys
($collection)¶Returns all keys of collection
Параметры:
- $collection –
array
,Iterator
Результат:
array
- static
combine
($keys, $values)¶Combines two collections to array.
Параметры:
- $keys –
array
,Iterator
- $values –
array
,Iterator
Результат:
array
,null
returns null if size of arrays is not equals.
- static
map
($collection, $callback)¶
Параметры:
- $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.
Параметры:
- $collection –
array
,Iterator
- $maxLevel –
int
Результат:
array
- static
sort
($collection, $comparator = null, $saveKeys = false)¶Sorts the specified list into ascending order
Параметры:
- $collection –
array
,Iterator
- $comparator –
callable
- ($o1, $o2) -> int where -1 smaller, 0 equal, 1 greater- $saveKeys –
bool
Результат:
array
- static
sortByKeys
($collection, $comparator = null, $saveKeys = false)¶Sorts the specified list into ascending order by keys
Параметры:
- $collection –
array
,Iterator
- $comparator –
callable
- ($key1, $key2)- $saveKeys –
bool
Результат:
array
- static
peak
($array)¶Returns the last element of array.
Параметры:
- $array –
Результат:
mixed
last value of array
- static
push
($array, $values)¶
Параметры:
- $array –
array
,ArrayAccess
- $values –
- static
pop
($array)¶
Параметры:
- $array –
array
Результат:
mixed
- static
shift
($array)¶
Параметры:
- $array –
array
Результат:
mixed
- static
unshift
($array, $values)¶
Параметры:
- $array –
array
- $values –
- static
first
($collection)¶
Параметры:
- $collection –
Traversable
,array
Результат:
mixed
- static
firstKey
($collection)¶
Параметры:
- $collection –
Traversable
,array
Результат:
string
,int
,null
- static
reverse
($array)¶
Параметры:
- $array –
array
Результат:
array