Index Documentation

XArray
in package

FinalYes

Provides various helper methods for collections.

Table of Contents

Constants

UNIQUE_NUMBER  = SORT_NUMERIC
Compare items items as numbers.
UNIQUE_STRING  = SORT_STRING
Compare items as strings.
UNIQUE_VALUE  = SORT_REGULAR
Compare items normally without type casting for uniqueness.

Methods

all()  : bool
Checks if all values in the collection match a given predicate.
any()  : bool
Checks if any value in the collection matches a given predicate.
contains()  : bool
Checks if an item occurs in a collection
containsKey()  : bool
Checks if a key occurs in a collection.
count()  : int
Retrieves the amount of items in a collection.
empty()  : bool
Checks if a collection has no items.
extractIterator()  : Iterator
Tries to extract an instance of Iterator from any iterable type.
first()  : mixed
Gets the first item in a collection that matches a given predicate.
firstKey()  : mixed
Retrieves the first key in a collection.
indexOf()  : mixed
Gets the index of a value in a collection.
last()  : mixed
Gets the last item in a collection that matches a given predicate.
lastKey()  : mixed
Retrieves the last key in a collection.
merge()  : array<string|int, mixed>
Merges two collections.
reflow()  : array<string|int, mixed>
Takes values from a collection and discards the keys.
reverse()  : array<string|int, mixed>
Puts a collection in reverse order.
select()  : array<string|int, T2>
Applies a modifier on a collection.
sequenceEquals()  : bool
Checks if two collections are equal in both keys and values.
slice()  : array<string|int, mixed>
Takes a subsection of a collection.
sort()  : array<string|int, T>
Sorts a collection according to a comparer.
toArray()  : array<string|int, mixed>
Converts any iterable to a PHP array.
unique()  : array<string|int, mixed>
Extracts unique values from a collection.
where()  : array<string|int, mixed>
Gets a subset of a collection based on a given predicate.

Constants

UNIQUE_NUMBER

Compare items items as numbers.

public int UNIQUE_NUMBER = SORT_NUMERIC

UNIQUE_STRING

Compare items as strings.

public int UNIQUE_STRING = SORT_STRING

UNIQUE_VALUE

Compare items normally without type casting for uniqueness.

public int UNIQUE_VALUE = SORT_REGULAR

Methods

all()

Checks if all values in the collection match a given predicate.

public static all(array<string|int, mixed> $iterable, callable(mixed): bool $predicate) : bool
Parameters
$iterable : array<string|int, mixed>
$predicate : callable(mixed): bool
Return values
bool

any()

Checks if any value in the collection matches a given predicate.

public static any(array<string|int, mixed> $iterable, callable(mixed): bool $predicate) : bool
Parameters
$iterable : array<string|int, mixed>
$predicate : callable(mixed): bool
Return values
bool

contains()

Checks if an item occurs in a collection

public static contains(array<string|int, mixed> $iterable, mixed $value[, bool $strict = false ]) : bool
Parameters
$iterable : array<string|int, mixed>
$value : mixed
$strict : bool = false
Return values
bool

containsKey()

Checks if a key occurs in a collection.

public static containsKey(array<string|int, mixed> $iterable, mixed $key) : bool
Parameters
$iterable : array<string|int, mixed>
$key : mixed
Return values
bool

count()

Retrieves the amount of items in a collection.

public static count(array<string|int, mixed> $iterable) : int
Parameters
$iterable : array<string|int, mixed>
Return values
int

empty()

Checks if a collection has no items.

public static empty(array<string|int, mixed> $iterable) : bool
Parameters
$iterable : array<string|int, mixed>
Return values
bool

extractIterator()

Tries to extract an instance of Iterator from any iterable type.

public static extractIterator(array<string|int, mixed> &$iterable) : Iterator
Parameters
$iterable : array<string|int, mixed>
Return values
Iterator

first()

Gets the first item in a collection that matches a given predicate.

public static first(array<string|int, mixed> $iterable[, callable(mixed): bool|null $predicate = null ]) : mixed
Parameters
$iterable : array<string|int, mixed>
$predicate : callable(mixed): bool|null = null

firstKey()

Retrieves the first key in a collection.

public static firstKey(array<string|int, mixed> $iterable) : mixed
Parameters
$iterable : array<string|int, mixed>

indexOf()

Gets the index of a value in a collection.

public static indexOf(array<string|int, mixed> $iterable, mixed $value[, bool $strict = false ]) : mixed
Parameters
$iterable : array<string|int, mixed>
$value : mixed
$strict : bool = false

last()

Gets the last item in a collection that matches a given predicate.

public static last(array<string|int, mixed> $iterable[, callable(mixed): bool|null $predicate = null ]) : mixed
Parameters
$iterable : array<string|int, mixed>
$predicate : callable(mixed): bool|null = null

lastKey()

Retrieves the last key in a collection.

public static lastKey(array<string|int, mixed> $iterable) : mixed
Parameters
$iterable : array<string|int, mixed>

merge()

Merges two collections.

public static merge(array<string|int, mixed> $iterable1, array<string|int, mixed> $iterable2) : array<string|int, mixed>
Parameters
$iterable1 : array<string|int, mixed>
$iterable2 : array<string|int, mixed>
Return values
array<string|int, mixed>

reflow()

Takes values from a collection and discards the keys.

public static reflow(array<string|int, mixed> $iterable) : array<string|int, mixed>
Parameters
$iterable : array<string|int, mixed>
Return values
array<string|int, mixed>

reverse()

Puts a collection in reverse order.

public static reverse(array<string|int, mixed> $iterable) : array<string|int, mixed>
Parameters
$iterable : array<string|int, mixed>
Return values
array<string|int, mixed>

select()

Applies a modifier on a collection.

public static select(array<string|int, T1$iterable, callable(T1): T2 $selector) : array<string|int, T2>
Parameters
$iterable : array<string|int, T1>
$selector : callable(T1): T2
Return values
array<string|int, T2>

sequenceEquals()

Checks if two collections are equal in both keys and values.

public static sequenceEquals(array<string|int, mixed> $iterable1, array<string|int, mixed> $iterable2) : bool
Parameters
$iterable1 : array<string|int, mixed>
$iterable2 : array<string|int, mixed>
Return values
bool

slice()

Takes a subsection of a collection.

public static slice(array<string|int, mixed> $iterable, int $offset[, int|null $length = null ]) : array<string|int, mixed>
Parameters
$iterable : array<string|int, mixed>
$offset : int
$length : int|null = null
Return values
array<string|int, mixed>

sort()

Sorts a collection according to a comparer.

public static sort(array<string|int, T$iterable, callable $comparer) : array<string|int, T>
Parameters
$iterable : array<string|int, T>
$comparer : callable
Return values
array<string|int, T>

toArray()

Converts any iterable to a PHP array.

public static toArray(array<string|int, mixed> $iterable) : array<string|int, mixed>
Parameters
$iterable : array<string|int, mixed>
Return values
array<string|int, mixed>

unique()

Extracts unique values from a collection.

public static unique(array<string|int, mixed> $iterable[, int $type = self::UNIQUE_VALUE ]) : array<string|int, mixed>
Parameters
$iterable : array<string|int, mixed>
$type : int = self::UNIQUE_VALUE
Return values
array<string|int, mixed>

where()

Gets a subset of a collection based on a given predicate.

public static where(array<string|int, mixed> $iterable, callable(mixed): bool $predicate) : array<string|int, mixed>
Parameters
$iterable : array<string|int, mixed>
$predicate : callable(mixed): bool
Return values
array<string|int, mixed>

        
On this page

Search results