src/Traits/Collections.php
public static function filter(array $array = [], Closure $closure = null): array
    {
        if ($closure) {
            $result = [];

            foreach ($array as $key => $value) {
                if (call_user_func($closure, $value)) {
                    $result[] = $value;
                }
            }

            return $result;
        }

        return __::compact($array);
    }
public static function filter(array $array = [], Closure $closure = null): array
    {
        if ($closure) {
            $result = [];

            foreach ($array as $key => $value) {
                if (call_user_func($closure, $value)) {
                    $result[] = $value;
                }
            }

            return $result;
        }

        return __::compact($array);
    }
public static function filter ( array $ array = [ ] , Closure $ closure = null ) : array { if ( $ closure ) { $ result = [ ] ; foreach ( $ array as $ key => $ value ) { if ( call_user_func ( $ closure , $ value ) ) { $ result [ ] = $ value ; } } return $ result ; } return __ :: compact ( $ array ) ; }
Returns the values in the collection that pass the truth test.

@param array    $array   array to filter
@param \Closure $closure closure to filter array based on

@return array
Returns the values in the collection that pass the truth test .