Minwork Array
  • Minwork Array
  • Common methods
    • has
    • get → getNestedElement
    • set → setNestedElement
    • remove
    • clone
    • getKeysArray
  • Object oriented methods
    • General information
  • Traversing array
    • Finding
    • Iterating
  • Manipulating array
    • Mapping
    • Filtering
    • Grouping
    • Sorting
    • Computations
    • Flattening
  • Validating array
    • check
    • isEmpty
    • isNested
    • isArrayOfArrays
    • isAssoc
    • isUnique
    • isNumeric
    • hasKeys
  • Utility methods
    • pack
    • unpack
    • createMulti
    • forceArray
    • getDepth
    • random
    • shuffle
    • nth
    • getFirstKey
    • getLastKey
    • getFirstValue
    • getLastValue
Powered by GitBook
On this page
  • filter
  • filterByKeys
  • filterObjects

Was this helpful?

  1. Manipulating array

Filtering

PreviousMappingNextGrouping

Last updated 5 years ago

Was this helpful?

filter

Definition

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

Description

Wrapper around PHP built-in method to allow in ArrObj

Examples

See

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

Arr::filterObjects(array $objects, string $method, ...$args): array

Description

Filter objects array using return value of specified method

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

Examples

$object = new class() { 
    function test($preserve = true) { 
        return $preserve;
    }
};

$array = [$object, 'foo', $object, false];

Arr::filterObjects($array, 'test') -> [$object, 'foo', $object]
Arr::filterObjects($array, 'test', false) -> ['foo']
array_filter
chaining
array_filter examples