function NestedArray::filter
Same name in other branches
- 9 core/lib/Drupal/Component/Utility/NestedArray.php \Drupal\Component\Utility\NestedArray::filter()
- 8.9.x core/lib/Drupal/Component/Utility/NestedArray.php \Drupal\Component\Utility\NestedArray::filter()
- 10 core/lib/Drupal/Component/Utility/NestedArray.php \Drupal\Component\Utility\NestedArray::filter()
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.
2 calls to NestedArray::filter()
- NestedArrayTest::testFilter in core/
tests/ Drupal/ Tests/ Component/ Utility/ NestedArrayTest.php - @covers ::filter @dataProvider providerTestFilter
- TestDiscovery::getTestClasses in core/
lib/ Drupal/ Core/ Test/ TestDiscovery.php - Discovers all available tests in all extensions.
File
-
core/
lib/ Drupal/ Component/ Utility/ NestedArray.php, line 361
Class
- NestedArray
- Provides helpers to perform operations on nested arrays and array keys of variable depth.
Namespace
Drupal\Component\UtilityCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.