Ouzo\Utilities\Arrays::filterByKeys PHP Method

filterByKeys() public static method

Example: $array = array('a1' => 1, 'a2' => 2, 'c' => 3); $filtered = Arrays::filterByKeys($array, function ($elem) { return $elem[0] == 'a'; }); Result: Array ( [a1] => 1 [b2] => 2 )
public static filterByKeys ( array $elements, callable $predicate ) : array
$elements array
$predicate callable
return array
    public static function filterByKeys(array $elements, $predicate)
    {
        $allowedKeys = array_filter(array_keys($elements), $predicate);
        return self::filterByAllowedKeys($elements, $allowedKeys);
    }

Usage Example

Esempio n. 1
0
 public function getRequestHeaders()
 {
     $headers = Arrays::filterByKeys($_SERVER, Functions::startsWith('HTTP_'));
     return Arrays::mapKeys($headers, function ($key) {
         return str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($key, 5)))));
     });
 }
All Usage Examples Of Ouzo\Utilities\Arrays::filterByKeys