Skip to content

Latest commit

 

History

History
292 lines (204 loc) · 5.32 KB

File metadata and controls

292 lines (204 loc) · 5.32 KB

arr

  • class arr (php\lib\arr)
  • package std
  • source php/lib/arr.php

Child Classes

items

Description

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


Static Methods

  • arr ::count() - Returns element count of the collection
  • arr ::has()
  • arr ::hasKey()
  • arr ::toArray() - Converts $collection to array
  • arr ::of() - Alias of toArray()
  • arr ::toList() - Example: items::toList(['x' => 10, 20], 30, ['x' => 50, 60]) -> [10, 20, 30, 50, 60]
  • arr ::keys() - Returns all keys of collection
  • arr ::values() - Returns all values of collection
  • arr ::combine() - Combines two collections to array.
  • arr ::map()
  • arr ::flatten() - Returns a new array that is a one-dimensional flattening of this collection (recursively).
  • arr ::sort() - Sorts the specified list into ascending order
  • arr ::sortByKeys() - Sorts the specified list into ascending order by keys
  • arr ::peak() - Returns the last element of array.
  • arr ::push()
  • arr ::pop()
  • arr ::shift()
  • arr ::unshift()
  • arr ::first()
  • arr ::firstKey()
  • arr ::last() - Alias to peek().
  • arr ::lastKey()
  • arr ::reverse()
  • arr ::merge()

Methods


Static Methods

count()

arr::count(array|Countable|Iterator $collection): int

Returns element count of the collection

.. warning:: for iterators it will iterate all elements to return the result


has()

arr::has(array|Traversable $collection, mixed $value, bool $strict): bool

hasKey()

arr::hasKey(array $array, mixed $key): bool

toArray()

arr::toArray(array|\Traversable $collection, bool $withKeys): array

Converts $collection to array


of()

arr::of(array|Iterator $collection, bool|false $withKeys): array

Alias of toArray()


toList()

arr::toList(mixed $collection, array $others): array

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


keys()

arr::keys(iterable|array $collection): array

Returns all keys of collection


values()

arr::values(array|Iterator $collection): array

Returns all values of collection


combine()

arr::combine(array|Iterator $keys, array|Iterator $values): array|null

Combines two collections to array.


map()

arr::map(array|Iterator $collection, callable $callback): void

flatten()

arr::flatten(array|Iterator $collection, int $maxLevel): array

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.


sort()

arr::sort(array|Iterator $collection, callable $comparator, bool $saveKeys): array

Sorts the specified list into ascending order


sortByKeys()

arr::sortByKeys(array|Iterator $collection, callable $comparator, bool $saveKeys): array

Sorts the specified list into ascending order by keys


peak()

arr::peak(mixed $array): mixed

Returns the last element of array.


push()

arr::push(array|ArrayAccess $array, mixed $values): void

pop()

arr::pop(array $array): mixed

shift()

arr::shift(array $array): mixed

unshift()

arr::unshift(array $array, mixed $values): void

first()

arr::first(Traversable|array $collection): mixed

firstKey()

arr::firstKey(Traversable|array $collection): string|int|null

last()

arr::last(array $collection): mixed

Alias to peek().


lastKey()

arr::lastKey(array $collection): string|int|null

reverse()

arr::reverse(array $array): array

merge()

arr::merge(array $array, array $others): array

Methods

__construct()

__construct(): void