【发布时间】:2014-11-04 02:38:48
【问题描述】:
我有一个数组,其中还有另一个数组。我需要取消设置子数组的索引。
array
0 =>
array
'country_id' => string '1' (length=1)
'description' => string 'test' (length=4)
1 =>
array
'country_id' => string '2' (length=1)
'description' => string 'sel' (length=5)
2 =>
array
'country_id' => string '3' (length=1)
'description' => string 'soul' (length=5)
现在我需要取消设置主数组的所有三个索引的country_id。我正在使用 PHP,我最初认为 unset 会做,直到我意识到我的数组是嵌套的。
我该怎么做?
【问题讨论】:
-
foreach($array as &$element){unset($element['country_id'];} -
foreach ($array as &$sub) unset($sub['country_id']);