我有一个看起来像这样的三维数组
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)
我正在尝试遍历数组并删除单元格people
中没有值的任何(即数组的第二级)[image]
。
我试过了
foreach($MyArray as $Key=>&$group){
foreach($group as &$staff){
if(!file_exists($staff['image'])){
unset($staff);
}
}
}
但这不会删除没有图像的数组项。该循环正确识别没有图像的员工,就好像我包含一些代码将它们回显到页面上一样,这是可行的。它只是没有从$MyArray
数组中取消它们。
谁能帮我实现这一目标?