我试图弄清楚如何删除一个主要元素及其所有兄弟姐妹,然后保存数组.
这是我得到的:
$my_array = Array ( [0] => Array ( [username] => Pete [userid] => 2 ) [1] => Array ( [username] => James [userid] => 4 ) [2] => Array ( [username] => John [userid] => 3 ) )
现在,我想要做的是删除我拥有用户ID 4的元素,然后将其全部保存回$my_array,如下所示:
$my_array = Array ( [0] => Array ( [username] => Pete [userid] => 2 ) [2] => Array ( [username] => John [userid] => 3 ) )
可以这样做吗?如果是的话……怎么样?
提前致谢 :-)
试试这个:
原文链接:https://www.f2er.com/php/130597.htmlforeach ($array as $key => $value) { if ($value["userid"] == 4) { unset($array[$key]); } }