I am struggling to figure out how to remove elements from a triple nested array based on a value at the deepest level. I would like to remove any position sub-array where time == "NA". My array structure is as follows.
Array
(
[0] => Array
(
[Id] => 151601
[First_Name] => JOHN
[Last_Name] => DOE
[Location_Id] => 10
[Positions] => Array
(
[North] => Array
(
[Current_Level] => 4
[Last_Date] => 11/7/2001
[Time] => 4:15 AM
)
[East] => Array
(
[Current_Level] => 4
[Last_Date] => 7/10/2003
[Time] => 7:30 PM
)
[South] => Array
(
[Current_Level] => 2
[Last_Date] => 8/10/2007
[Time] => NA
)
[West] => Array
(
[Current_Level] => NA
[Last_Date] => NA
[Time] => NA
)
)
)
So my end result would be
Array
(
[0] => Array
(
[Id] => 151601
[First_Name] => JOHN
[Last_Name] => DOE
[Location_Id] => 10
[Positions] => Array
(
[North] => Array
(
[Current_Level] => 4
[Last_Date] => 11/7/2001
[Time] => 4:15 AM
)
[East] => Array
(
[Current_Level] => 4
[Last_Date] => 7/10/2003
[Time] => 7:30 PM
)
)
)
This is what I am currently trying but it is throwing an illegal offset type error. I think I'm just not unsetting the right thing. I can get it to echo all the correct subarrays but when I try to unset I get an offset error.
foreach($records as $record) {
foreach ($record as $value) {
if (is_array($value)) {
foreach ($value as $position) {
if($position["Time"] == "NA") {
unset($records[$record][$value]);
}
}
}
}
}