I have a three dimensional array that looks like this
Array(
[Group 1] => Array
(
[0] => Array
(
[category] => Group1
[firstname] => John
[lastname] => Johns
[image] => /mysite.etc/jj.jpg
)
[1] => Array
(
[category] => Group1
[firstname] => John
[lastname] => James
[image] => /mysite.etc/jj2.jpg
)
)
[Group 2] => Array
(
[0] => Array
(
[category] => Group2
[firstname] => John
[lastname] => Jackson
[image] => NULL
)
[1] => Array
(
[category] => Group2
[firstname] => John
[lastname] => Jimson
[image] => /mysite.etc/jj4.jpg
)
)...etc)
I'm trying to loop through the array and remove any people
(i.e. the second level of the array) who do not have a value in the [image]
cell.
I've tried
foreach($MyArray as $Key=>&$group){
foreach($group as &$staff){
if(!file_exists($staff['image'])){
unset($staff);
}
}
}
but this does not remove the array items with no image. The loop is correctly identifying the staff with no image as if I include a bit of code to echo them onto the page, this works. It's just not unsetting them from the $MyArray
array.
Can anyone help me achieve this?