I'm trying to remove arrays in array who contain specific keys.
I would like to remove arrays who contain :
[code] => 404
[message] => The exhibitor has no validated order.
Example :
Array
(
[0] => Array
(
[id] => 2924
[id_dossier] => 26169
)
[1] => Array
(
[code] => 404
[message] => The exhibitor has no validated order.
)
[2] => Array
(
[code] => 404
[message] => The exhibitor has no validated order.
)
[3] => Array
(
[id] => 3469
[id_dossier] => 27831
)
)
And I would like output like this :
Array
(
[0] => Array
(
[id] => 2924
[id_dossier] => 26169
)
[1] => Array
(
[id] => 3469
[id_dossier] => 27831
)
)
I tried with : array_filter
:
$final_array = array_filter($final_array, function ($var) {
return $var['code'] != '404';
});
And I tried with a foreach
:
foreach ($final_array as $thisArrIndex=>$subArray) {
if ($subArray['code'] == "404" ) {
unset($final_array[$thisArrIndex]);
}
}
My output is good but I got a notice :
Notice : Undefined index: code in .....
What's wrong please ? Thank you in advance