I have an array like this:
$_SESSION['food'] = array(
// ARRAY 1
array(
"name" => "apple",
"shape" => "round",
"color" => "red"
),
// ARRAY 2
array(
"name" => "banana",
"shape" => "long",
"color" => "yellow"
)
);
I want to search through all keys in all child arrays and delete the entire child array if the search term is found.
So, basically:
How would I accomplish this?
Thanks!
This should do the trick:
foreach ($array as $key => $value) {
foreach ($value as $child_value) {
if ($child_value == $search_term) {
unset($array[$key]);
continue 2;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With