How can I remove value "288" from "pecan" and return the updated array.
Array like so:
a: 10: {
s: 13: "Fraser Island";
a: 7: {
i: 0;
i: 303;
i: 1;
i: 34;
i: 2;
i: 27;
i: 3;
i: 291;
i: 4;
i: 293;
i: 5;
i: 37;
i: 6;
i: 288;
}
s: 5: "pecan";
a: 5: {
i: 0;
i: 34;
i: 1;
i: 27;
i: 2;
i: 291;
i: 3;
i: 59;
i: 4;
i: 288;
}
s: 11: "New Triper";
a: 3: {
i: 0;
i: 291;
i: 1;
i: 293;
i: 2;
i: 288;
}
}
Which translates to this in PHP:
Array (
[0] => Array (
[Fraser Island] => Array (
[0] => 303
[1] => 34
[2] => 27
[3] => 291
[4] => 293
[5] => 37
[6] => 288
)
[pecan] => Array (
[0] => 34
[1] => 27
[2] => 291
[3] => 59
[4] => 288
)
[New Triper!] => Array (
[0] => 291
[1] => 293
[2] => 288
)
)
)
Delete/remove a value from a multidimensional array by finding the array column name and the value. I use this code:
// DELETE VALUE FROM ARRAY
function remove_element_by_value($arr, $val) {
$return = array();
foreach($arr as $k => $v) {
if(is_array($v)) {
$return[$k] = remove_element_by_value($v, $val); //recursion
continue;
}
if($v == $val) continue;
$return[$k] = $v;
}
return $return;
}
However it removes all matching values from all array columns.
$a = array("foo", "bar", "orange"); $a = 0; $a = array("foo", "bar");