ArrayViewInterface
extends
ArrayAccess, IteratorAggregate, Countable
in
Interface for a view of an array with additional methods for filtering, mapping, and transforming the data.
Tags
Table of Contents
Methods
- apply() : ArrayViewInterface<string|int, T>
- Applies a transformation function to each element in the view.
- applyWith() : ArrayViewInterface<string|int, T>
- Applies a transformation function using another array or view as rhs values for a binary operation.
- count() : int
- Return size of the view.
- filter() : ArrayViewInterface<string|int, T>
- Filters the elements in the view based on a predicate function.
- getIterator() : Generator<int, T>
- Return iterator to iterate the view elements.
- is() : MaskSelectorInterface
- Checks if all elements in the view satisfy a given predicate function.
- isReadonly() : bool
- Return true if view is readonly, otherwise false.
- map() : array<string|int, T>
- Transforms each element of the array using the given callback function.
- mapWith() : array<string|int, mixed>
- Transforms each pair of elements from the current array view and the provided data array using the given callback function.
- match() : MaskSelectorInterface
- Checks if all elements in the view satisfy a given predicate function.
- matchWith() : MaskSelectorInterface
- Compares the elements of the current ArrayView instance with another array or ArrayView using the provided comparator function.
- offsetExists() : bool
- offsetGet() : T|array<string|int, T>
- offsetSet() : void
- offsetUnset() : void
- set() : ArrayViewInterface<string|int, T>
- Sets new values for the elements in the view.
- subview() : ArrayViewInterface<string|int, T>
- Returns a subview of this view based on a selector or string slice.
- toArray() : array<string|int, T>
- Returns the array representation of the view.
- toUnlinkedView() : ArrayViewInterface<string|int, T>
- Creates an unlinked from source ArrayView instance from the given source array or ArrayView.
- toView() : ArrayViewInterface<string|int, T>
- Creates an ArrayView instance from the given source array or ArrayView.
Methods
apply()
Applies a transformation function to each element in the view.
public
apply(callable(T, int): T $mapper) : ArrayViewInterface<string|int, T>
Parameters
- $mapper : callable(T, int): T
-
Function to transform each element.
Return values
ArrayViewInterface<string|int, T> —this view.
applyWith()
Applies a transformation function using another array or view as rhs values for a binary operation.
public
applyWith(array<string|int, U>|ArrayViewInterface<string|int, U> $data, callable(T, U, int): T $mapper) : ArrayViewInterface<string|int, T>
Parameters
- $data : array<string|int, U>|ArrayViewInterface<string|int, U>
-
The rhs values for a binary operation.
- $mapper : callable(T, U, int): T
-
Function to transform each pair of elements.
Tags
Return values
ArrayViewInterface<string|int, T> —this view.
count()
Return size of the view.
public
count() : int
Return values
intfilter()
Filters the elements in the view based on a predicate function.
public
filter(callable(T, int): bool $predicate) : ArrayViewInterface<string|int, T>
Parameters
- $predicate : callable(T, int): bool
-
Function that returns a boolean value for each element.
Return values
ArrayViewInterface<string|int, T> —A new view with elements that satisfy the predicate.
getIterator()
Return iterator to iterate the view elements.
public
getIterator() : Generator<int, T>
Return values
Generator<int, T>is()
Checks if all elements in the view satisfy a given predicate function.
public
is(callable(T, int): bool $predicate) : MaskSelectorInterface
Parameters
- $predicate : callable(T, int): bool
-
Function that returns a boolean value for each element.
Tags
Return values
MaskSelectorInterface —Boolean mask for selecting elements that satisfy the predicate.
isReadonly()
Return true if view is readonly, otherwise false.
public
isReadonly() : bool
Return values
boolmap()
Transforms each element of the array using the given callback function.
public
map(callable(T, int): T $mapper) : array<string|int, T>
The callback function receives two parameters: the current element of the array and its index.
Parameters
- $mapper : callable(T, int): T
-
Function to transform each element.
Return values
array<string|int, T> —New array with transformed elements of this view.
mapWith()
Transforms each pair of elements from the current array view and the provided data array using the given callback function.
public
mapWith(array<string|int, U>|ArrayViewInterface<string|int, U>|U $data, callable(T, U, int): T $mapper) : array<string|int, mixed>
The callback function receives three parameters: the current element of the current array view, the corresponding element of the data array, and the index.
Parameters
- $data : array<string|int, U>|ArrayViewInterface<string|int, U>|U
-
The rhs values for a binary operation.
- $mapper : callable(T, U, int): T
-
Function to transform each pair of elements.
Tags
Return values
array<string|int, mixed> —New array with transformed elements of this view.
match()
Checks if all elements in the view satisfy a given predicate function.
public
match(callable(T, int): bool $predicate) : MaskSelectorInterface
Parameters
- $predicate : callable(T, int): bool
-
Function that returns a boolean value for each element.
Tags
Return values
MaskSelectorInterface —Boolean mask for selecting elements that satisfy the predicate.
matchWith()
Compares the elements of the current ArrayView instance with another array or ArrayView using the provided comparator function.
public
matchWith(array<string|int, U>|ArrayViewInterface<string|int, U>|U $data, callable(T, U, int): bool $comparator) : MaskSelectorInterface
Parameters
- $data : array<string|int, U>|ArrayViewInterface<string|int, U>|U
-
The array or ArrayView to compare to.
- $comparator : callable(T, U, int): bool
-
Function that determines the comparison logic between the elements.
Tags
Return values
MaskSelectorInterface —A MaskSelector instance representing the results of the element comparisons.
offsetExists()
public
offsetExists((numeric)|string|ArraySelectorInterface $offset) : bool
Parameters
- $offset : (numeric)|string|ArraySelectorInterface
Return values
bool —offsetGet()
public
offsetGet((numeric)|string|ArraySelectorInterface $offset) : T|array<string|int, T>
Parameters
- $offset : (numeric)|string|ArraySelectorInterface
Tags
Attributes
- #[ReturnTypeWillChange]
Return values
T|array<string|int, T>offsetSet()
public
offsetSet((numeric)|string|ArraySelectorInterface $offset, T|array<string|int, T>|ArrayViewInterface<string|int, T> $value) : void
Parameters
- $offset : (numeric)|string|ArraySelectorInterface
- $value : T|array<string|int, T>|ArrayViewInterface<string|int, T>
Tags
offsetUnset()
public
offsetUnset((numeric)|string|ArraySelectorInterface $offset) : void
Parameters
- $offset : (numeric)|string|ArraySelectorInterface
Tags
set()
Sets new values for the elements in the view.
public
set(array<string|int, T>|ArrayViewInterface<string|int, T>|T $newValues) : ArrayViewInterface<string|int, T>
Parameters
- $newValues : array<string|int, T>|ArrayViewInterface<string|int, T>|T
-
The new values to set.
Tags
Return values
ArrayViewInterface<string|int, T> —this view.
subview()
Returns a subview of this view based on a selector or string slice.
public
subview(string|array<string|int, int|bool>|ArrayViewInterface<string|int, int|bool>|ArraySelectorInterface $selector[, bool|null $readonly = null ]) : ArrayViewInterface<string|int, T>
Parameters
- $selector : string|array<string|int, int|bool>|ArrayViewInterface<string|int, int|bool>|ArraySelectorInterface
-
The selector or string to filter the subview.
- $readonly : bool|null = null
-
Flag indicating if the subview should be read-only.
Tags
Return values
ArrayViewInterface<string|int, T> —A new view representing the subview of this view.
toArray()
Returns the array representation of the view.
public
toArray() : array<string|int, T>
Return values
array<string|int, T> —The array representation of the view.
toUnlinkedView()
Creates an unlinked from source ArrayView instance from the given source array or ArrayView.
public
static toUnlinkedView(array<string|int, T>|ArrayViewInterface<string|int, T> $source[, bool|null $readonly = null ]) : ArrayViewInterface<string|int, T>
- If the source is not an ArrayView, a new ArrayView is created with the provided source.
- If the source is an ArrayView and the
readonly
parameter is specified astrue
, a new readonly ArrayView is created. - If the source is an ArrayView and it is already readonly, the same ArrayView is returned.
Parameters
- $source : array<string|int, T>|ArrayViewInterface<string|int, T>
-
The source array or ArrayView to create a view from.
- $readonly : bool|null = null
-
Optional flag to indicate whether the view should be readonly.
Tags
Return values
ArrayViewInterface<string|int, T> —An ArrayView instance based on the source array or ArrayView.
toView()
Creates an ArrayView instance from the given source array or ArrayView.
public
static toView(array<string|int, T>|ArrayViewInterface<string|int, T> &$source[, bool|null $readonly = null ]) : ArrayViewInterface<string|int, T>
- If the source is not an ArrayView, a new ArrayView is created with the provided source.
- If the source is an ArrayView and the
readonly
parameter is specified astrue
, a new readonly ArrayView is created. - If the source is an ArrayView and it is already readonly, the same ArrayView is returned.
Parameters
- $source : array<string|int, T>|ArrayViewInterface<string|int, T>
-
The source array or ArrayView to create a view from.
- $readonly : bool|null = null
-
Optional flag to indicate whether the view should be readonly.
Tags
Return values
ArrayViewInterface<string|int, T> —An ArrayView instance based on the source array or ArrayView.