src/Stdlib/ArrayUtils.php
public static function filterRecursive(array $array, $callback = null, $removeEmptyArrays = false)
    {
        if (null !== $callback && !is_callable($callback)) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Second parameter of %s must be callable',
                __METHOD__
            ));
        }

        foreach ($array as $key => &$value) { // mind the reference
            if (is_array($value)) {
                $value = static::filterRecursive($value, $callback, $removeEmptyArrays);

                if ($removeEmptyArrays && ! (bool) $value) {
                    unset($array[$key]);
                }
            } else {
                if (null !== $callback && !$callback($value)) {
                    unset($array[$key]);
                } elseif (! (bool) $value) {
                    unset($array[$key]);
                }
            }
        }

        unset($value); // kill the reference

        return $array;
    }
public static function filterRecursive(array $array, $callback = null, $removeEmptyArrays = false)
    {
        if (null !== $callback && !is_callable($callback)) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Second parameter of %s must be callable',
                __METHOD__
            ));
        }

        foreach ($array as $key => &$value) { // mind the reference
            if (is_array($value)) {
                $value = static::filterRecursive($value, $callback, $removeEmptyArrays);

                if ($removeEmptyArrays && ! (bool) $value) {
                    unset($array[$key]);
                }
            } else {
                if (null !== $callback && !$callback($value)) {
                    unset($array[$key]);
                } elseif (! (bool) $value) {
                    unset($array[$key]);
                }
            }
        }

        unset($value); // kill the reference

        return $array;
    }
public static function filterRecursive ( array $ array , $ callback = null , $ removeEmptyArrays = false ) { if ( null !== $ callback && ! is_callable ( $ callback ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'Second parameter of %s must be callable' , __METHOD__ ) ) ; } foreach ( $ array as $ key => & $ value ) { // mind the reference if ( is_array ( $ value ) ) { $ value = static :: filterRecursive ( $ value , $ callback , $ removeEmptyArrays ) ; if ( $ removeEmptyArrays && ! ( bool ) $ value ) { unset ( $ array [ $ key ] ) ; } } else { if ( null !== $ callback && ! $ callback ( $ value ) ) { unset ( $ array [ $ key ] ) ; } elseif ( ! ( bool ) $ value ) { unset ( $ array [ $ key ] ) ; } } } unset ( $ value ) ; // kill the reference return $ array ; }
Exactly the same as array_filter except this function
filters within multi-dimensional arrays

@param array $array
@param callable $callback optional callback function name
@param bool $removeEmptyArrays optional flag removal of empty arrays after filtering
@return array
Exactly the same as array_filter except this function filters within multi - dimensional arrays