$array = array('a1' => 1, 'a2' => 2, 'c' => 3); $filtered = Arrays::filterByKeys($array, function ($elem) { return $elem[0] == 'a'; });
Array ( [a1] => 1 [b2] => 2 )
public static function filterByKeys(array $elements, $predicate) { $allowedKeys = array_filter(array_keys($elements), $predicate); return self::filterByAllowedKeys($elements, $allowedKeys); }
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))))); }); }