Documentation

MaskSelector
in package
implements MaskSelectorInterface

FinalYes

Represents a mask selector that selects elements based on the provided array of boolean mask values.

$originalArray = [1, 2, 3, 4, 5];
$view = ArrayView::toView($originalArray);

$selector = new MaskSelector([true, false, true, false, true]);
print_r($view[$selector]); // [1, 3, 5]
print_r($view->subview($selector)->toArray()); // [1, 3, 5]

Table of Contents

Interfaces

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

Methods

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

Methods

__construct()

Creates a new MaskSelector instance with the provided array of boolean mask values.

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

The array or array view of boolean mask values.

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 boolean mask array.

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

select()

Selects elements from the source array based on the mask values.

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

The source array 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
ArrayMaskView<string|int, T>

The view containing the selected elements.


        
On this page

Search results