Documentation

IndexListSelector
in package
implements IndexListSelectorInterface

FinalYes

Represents an index list selector that selects elements based on the provided array of indexes.

$originalArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
$view = ArrayView::toView($originalArray);

$selector = new IndexListSelector([0, 2, 4]);
print_r($view[$selector]); // [1, 3, 5]
print_r($view->subview($selector)->toArray()); // [1, 3, 5]

Table of Contents

Interfaces

IndexListSelectorInterface
Interface for selecting elements from an array view by boolean mask.

Methods

__construct()  : mixed
Creates a new IndexListSelector instance with the provided array of indexes.
compatibleWith()  : bool
Checks if the selector is compatible with the given view.
getValue()  : array<string|int, int>
Return index list array.
select()  : ArrayIndexListView<string|int, T>
Selects elements from the source array based on the index list.

Methods

__construct()

Creates a new IndexListSelector instance with the provided array of indexes.

public __construct(array<string|int, int>|ArrayViewInterface<string|int, int> $value) : mixed
Parameters
$value : array<string|int, int>|ArrayViewInterface<string|int, int>

The array of indexes or array view containing indexes.

compatibleWith()

Checks if the selector is compatible with the given view.

public compatibleWith(ArrayViewInterface<string|int, T$view) : bool
Parameters
$view : ArrayViewInterface<string|int, T>

the view to check compatibility with.

Tags
template

T View elements type.

Return values
bool

true if the element is compatible, false otherwise

getValue()

Return index list array.

public getValue() : array<string|int, int>
Return values
array<string|int, int>

select()

Selects elements from the source array based on the index list.

public select(ArrayViewInterface<string|int, T$source[, bool|null $readonly = null ]) : ArrayIndexListView<string|int, T>
Parameters
$source : ArrayViewInterface<string|int, T>

The source array view to select elements from.

$readonly : bool|null = null

Whether the selection should be read-only.

Tags
template

T The type of elements in the source array view.

Return values
ArrayIndexListView<string|int, T>

The view containing the selected elements.


        
On this page

Search results