W3cubDocs

/Drupal 8

public static function NestedArray::filter

public static NestedArray::filter(array $array, callable $callable = NULL)

Filters a nested array recursively.

Parameters

array $array: The filtered nested array.

callable|NULL $callable: The callable to apply for filtering.

Return value

array The filtered array.

File

core/lib/Drupal/Component/Utility/NestedArray.php, line 358

Class

NestedArray
Provides helpers to perform operations on nested arrays and array keys of variable depth.

Namespace

Drupal\Component\Utility

Code

public static function filter(array $array, callable $callable = NULL) {
  $array = is_callable($callable) ? array_filter($array, $callable) : array_filter($array);
  foreach ($array as &$element) {
    if (is_array($element)) {
      $element = static::filter($element, $callable);
    }
  }

  return $array;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Utility!NestedArray.php/function/NestedArray::filter/8.1.x