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()  : int|string|null
Retrieves the first key in a collection.
indexOf()  : int|string|false
Gets the index of a value in a collection.
last()  : mixed
Gets the last item in a collection that matches a given predicate.
lastKey()  : int|string|null
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, mixed>
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, mixed>
Sorts a collection according to a comparer.
toArray()  : array<string|int, mixed>
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(iterable<string|int, mixed> $iterable, callable $predicate) : bool
Parameters
$iterable : iterable<string|int, mixed>
$predicate : callable
Return values
bool

any()

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

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

contains()

Checks if an item occurs in a collection

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

containsKey()

Checks if a key occurs in a collection.

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

count()

Retrieves the amount of items in a collection.

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

empty()

Checks if a collection has no items.

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

extractIterator()

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

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

first()

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

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

firstKey()

Retrieves the first key in a collection.

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

indexOf()

Gets the index of a value in a collection.

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

last()

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

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

lastKey()

Retrieves the last key in a collection.

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

merge()

Merges two collections.

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

reflow()

Takes values from a collection and discards the keys.

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

reverse()

Puts a collection in reverse order.

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

select()

Applies a modifier on a collection.

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

sequenceEquals()

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

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

slice()

Takes a subsection of a collection.

public static slice(iterable<string|int, mixed> $iterable, int $offset[, int|null $length = null ]) : array<string|int, mixed>
Parameters
$iterable : iterable<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(iterable<string|int, mixed> $iterable, callable $comparer) : array<string|int, mixed>
Parameters
$iterable : iterable<string|int, mixed>
$comparer : callable
Return values
array<string|int, mixed>

toArray()

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

unique()

Extracts unique values from a collection.

public static unique(iterable<string|int, mixed> $iterable[, int $type = self::UNIQUE_VALUE ]) : array<string|int, mixed>
Parameters
$iterable : iterable<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(iterable<string|int, mixed> $iterable, callable $predicate) : array<string|int, mixed>
Parameters
$iterable : iterable<string|int, mixed>
$predicate : callable
Return values
array<string|int, mixed>

        
On this page

Search results