According to the PHP Manual, the preg_grep
function returns the entries of a array
that match the regular expression.
Example
$array = [
'Banana',
'Maçã',
'Café',
'Biscoito',
];
$array_com_B = preg_grep('/^B/i', $array);
Result:
['Banana', 'Biscoito']
But there is no function with this functionality to look up the indexes of a array
that matches a regular expression.
I would like to return the keys of the array
sampled below that match the regular expression /^(id|nome)$/i
.
[
'id' => 3,
'idade' => 25,
'nome' => 'Wallace de Souza',
'profissão' => 'Programador',
]