Documentation

ArrayViewInterface extends ArrayAccess, IteratorAggregate, Countable

Interface for a view of an array with additional methods for filtering, mapping, and transforming the data.

Tags
template

T The type of elements in the array

extends

\ArrayAccess<int|string|array<int|bool>|ArrayViewInterface<int|bool>|ArraySelectorInterface, T|array<T>>

extends

\IteratorAggregate<int, T>

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

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 $mapper) : ArrayViewInterface<string|int, T>
Parameters
$data : array<string|int, U>|ArrayViewInterface<string|int, U>

The rhs values for a binary operation.

$mapper : callable
Tags
template

U The type rhs of a binary operation.

throws
ValueError

if the $data is not sequential array.

throws
SizeError

if size of $data not equals to size of the view.

Return values
ArrayViewInterface<string|int, T>

this view.

filter()

Filters the elements in the view based on a predicate function.

public filter(callable $predicate) : ArrayViewInterface<string|int, T>
Parameters
$predicate : callable
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>

isReadonly()

Return true if view is readonly, otherwise false.

public isReadonly() : bool
Return values
bool

map()

Transforms each element of the array using the given callback function.

public map(callable $mapper) : array<string|int, T>

The callback function receives two parameters: the current element of the array and its index.

Parameters
$mapper : callable
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 $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
Tags
template

U The type rhs of a binary operation.

throws
ValueError

if the $data is not sequential array.

throws
SizeError

if size of $data not equals to size of the view.

Return values
array<string|int, mixed>

New array with transformed elements of this view.

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 $comparator) : MaskSelectorInterface
Parameters
$data : array<string|int, U>|ArrayViewInterface<string|int, U>|U

The array or ArrayView to compare to.

$comparator : callable
Tags
template

U The type of the elements in the array for comparison with.

throws
ValueError

if the $data is not sequential array.

throws
SizeError

if size of $data not equals to size of the view.

Return values
MaskSelectorInterface

A MaskSelector instance representing the results of the element comparisons.

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
throws
ValueError

if the $newValues is not sequential array.

throws
SizeError

if size of $newValues not equals to size of the view.

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
throws
IndexError

if the selector is IndexListSelector and some indexes are out of range.

throws
SizeError

if the selector is MaskSelector and size of the mask not equals to size of the view.

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 as true, 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
throws
ValueError

if the array is not sequential.

throws
ReadonlyError

if the source is readonly and trying to create a non-readonly view.

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 as true, 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
throws
ValueError

if the array is not sequential.

throws
ReadonlyError

if the source is readonly and trying to create a non-readonly view.

Return values
ArrayViewInterface<string|int, T>

An ArrayView instance based on the source array or ArrayView.


        
On this page

Search results