工作,我有這樣的用正則表達式匹配數組鍵沒有在PHP
Array (
[test.0.male_min_months] => Array (
[0] => The test.0.male_min_months field has a duplicate value.
)
[test.42.male_min_months] => Array (
[0] => The test.42.male_min_months field has a duplicate value.
)
[name] => Array (
[0] => The name field is required.
)
[unit_id] => Array (
[0] => The unit id field is required.
)
)
,並檢查在數組鍵的功能陣列
function preg_array_key_exists($pattern, $array) {
$keys = array_keys($array);
return $array[preg_grep($pattern,$keys)[0]];
}
其爲preg_array_key_exists('/(test.0.male)/',$my_array);
但工作不工作preg_array_key_exists('/(test.42.male)/',$my_array);
隨意downvote,但請解釋。 –
你見過:http://php.net/manual/en/function.preg-grep.php#111673? – Rizier123