This is my array.
I am trying to locate a specific date and remove that entire key from the array (both corresponding start_time and end_time.
$c = array
// Search all end_times
$remove = '2012-06-24 17:00:59';
array(2) {
[0]=>
array(2) {[0]=>
array(2) {[“ID”]=> string(2) “15”
[“start_time”]=> string(19) “2012-06-24 08:00:00”}
[1]=>
array(2) {[“ID”]=> string(2) “15”
[“end_time”]=> string(19) “2012-06-24 17:00:59”}
}
[1]=>
array(2) {[0]=>
array(2) {[“ID”]=> string(2) “28”
[“start_time”]=> string(19) “2012-07-26 18:00:00”}
[1]=>
array(2) {[“ID”]=> string(2) “28”
[“end_time”]=> string(19) “2012-07-26 22:00:59”}
}
}
This is the code I have so far. It works only when targeting the first start_time, or the second end_time, which suggests to me that the count is getting lost somewhere. I’m pretty new to PHP so I have very little clue as to whats next.
// recursive array search, look for value, remove key
for ($i = 0, $count = count($c); $i < $count; $i++) {
if ($c[$i][$i]['end_time'] == $remove) {
unset($c[$i]);
}
}
Would appreciate any help on this!
Regards
Should do what you’re looking for, if I understand correctly.
EDIT: Basically what it does is take each member of the original array and search each member of that parent array for the remove time. If it finds it, it removes the entire “tree.”