1
According to the PHP Handbook, the function preg_grep
returns the entries of a array
which combine with regular expression.
Example
$array = [
'Banana',
'Maçã',
'Café',
'Biscoito',
];
$array_com_B = preg_grep('/^B/i', $array);
Upshot:
['Banana', 'Biscoito']
But there is no function with this feature to search the contents of a array
to match a regular expression.
I’d like to return the keys to the array
exemplified below that match the regular expression /^(id|nome)$/i
.
[
'id' => 3,
'idade' => 25,
'nome' => 'Wallace de Souza',
'profissão' => 'Programador',
]
+1. I see much this call from
array_intersect_key
witharray_flip
in the source codes ofLaravel 4
.– Wallace Maxters