I have a multidimensional array like this:
[0] => Array
(
[abc] => value
[def] => value
)
[1] => Array
(
[abc] => value 2
[def] => value
)
In this case, I want to remove array 1
IF the values of [def]
match. How can I remove an array if the values match?
You could use array_search
for this. Something like this in your loop
if (($key = array_search($delete_value, $your_array)) !== false) {
unset($your_array[$key]);
}
You can simply go loop through your array and unset match index like this,
<?php
$arr = Array(Array(
'abc' => "value",
'def' => "value"
),Array(
'abc' => "value 2",
'def' => "value"
));
for($i = 0; $i < count($arr); $i++){
if($arr[$i]['def'] == $arr[$i+1]['def']){
unset($arr[$i+1]);
}
}
print_r($arr);
?>
Check this i have created demo link. I hope it helps.