1
我有一个多维数组称为$item_list
:删除多维元素未出现在另一个阵列中的数组?
Array
(
[0] => Array
(
[id] => 12
[customer] => Joe Bloggs
[details] => Text
)
[1] => Array
(
[id] => 13
[customer] => Fred Smith
[details] => Text
)
[2] => Array
(
[id] => 14
[customer] => John Doe
[details] => Text
)
)
我有不同的数据库(因此,没有SQL解决方案)另一个数组称为$id_list
其持有$item_list
的ID,我想保持:
Array
(
[0] => 12
[1] => 14
)
有没有办法通过比较$item_list[1]['id']
与$id_list
中的元素来删除$item_list[1]
而不用手动迭代$item_list
使用foreach()
或类似的阵列?
我仍然不明白'array_filter()',但你的解决方案完美地工作,非常感谢你:) – Kalessin 2011-03-17 19:34:28
@Kalessin,'array_filter'只是迭代传递的数组,为每个元素调用指定的函数。如果该函数调用对该元素返回“true”,它将包含在返回的列表中。为了简洁起见,我使用了一个匿名函数,但是您可以使用独立函数并按名称引用它。 – Matthew 2011-03-17 19:39:28