如何删除多维数组中指定元素?
程序员文章站
2022-05-28 17:24:15
...
[0] => Array ( [v] => 1 [fup] => 0 [n] => 服务器 [s] => Array ( [0] => Array ( [v] => 2 [fup] => 2 [n] => one [s] => Array ( [0] => Array ( [v] => 3 [fup] => 41 [n] => one ) [1] => Array ( [v] => 4 [fup] => 1 [n] => two ) [2] => Array ( [v] => 5 [fup] => 1 [n] => three ) ) ) [1] => Array ( [v] => 42 [fup] => 2 [n] => two [s] => Array ( [0] => Array ( [v] => 73 [fup] => 42 [n] => one ) [1] => Array ( [v] => 74 [fup] => 42 [n] => two ) [2] => Array ( [v] => 75 [fup] => 42 [n] => three ) ) ) [2] => Array ( [v] => 43 [fup] => 2 [n] => three ) ) )
我想把这个多维数组中的 [fup] => '' 都删掉,应该怎么写??
回复讨论(解决方案)
是删掉所有的 fup 项吗?递归呀!
$ar = 你的数组;foo($ar);function foo(&$ar) { foreach($ar as &$r) { if(isset($r['fup'])) unset($r['fup']); if(isset($r['s'])) foo($r['s']); }}
是删掉所有的 fup 项吗?递归呀!
$ar = 你的数组;foo($ar);function foo(&$ar) { foreach($ar as &$r) { if(isset($r['fup'])) unset($r['fup']); if(isset($r['s'])) foo($r['s']); }}
我是菜鸟,php是自学,所以递归这些还没写会
是的,删除所有的,fup项,我刚测试下为什么执行呢,什么结果都没有,那我要返回删除后的完整数组应该怎么写?
谢谢大神,试出来了
你打印出来看呀!你主贴中的不是你打印出来的吗?