Filtering

filter

Definition

Arr::filter(array $array, ?callable $callback = null, int $flag = 0): array

Description

Wrapper around PHP built-in array_filter method to allow chaining in ArrObj

Examples

See array_filter examples

filterByKeys

Definition

Arr::filterByKeys(array $array, mixed $keys, bool $exclude = false): array

Description

Filter array values by preserving only those which keys are present in array obtained from $keys variable

Examples

$array = [
    'a' => 1, 
    'b' => 2, 
    3 => 'c', 
    4 => 5
];

Arr::filterByKeys($array, 'a.b.3') -> ['a' => 1, 'b' => 2, 3 => 'c']
Arr::filterByKeys($array, 'a.b.3', true) -> [4 => 5]

Arr::filterByKeys($array, [null, 0, '']) -> []
Arr::filterByKeys($array, [null, 0, ''], true) -> $array

filterObjects

Definition

Description

Filter objects array using return value of specified method

This method also filter values other than objects by standard boolean comparison

Examples

Last updated

Was this helpful?