我正试图找出如何删除一个主要元素和所有的兄弟姐妹和保存数组之后。
这是我得到的:
$my_array = Array
(
[0] => Array
(
[username] => Pete
[userid] => 2
)
[1] => Array
(
[username] => James
[userid] => 4
)
[2] => Array
(
[username] => John
[userid] => 3
)
)
现在,我要做的是删除userid为4的元素然后将其保存回$my_array中,如下所示:
$my_array = Array
(
[0] => Array
(
[username] => Pete
[userid] => 2
)
[2] => Array
(
[username] => John
[userid] => 3
)
)
这能做到吗?如果是的话……如何? ?
提前感谢:-)
试试这个:
foreach ($array as $key => $value) {
if ($value["userid"] == 4) { unset($array[$key]); }
}