首页 >后端开发 >php教程 >如何删除多维数组中指定元素?

如何删除多维数组中指定元素?

WBOY
WBOY原创
2016-06-23 13:53:151494浏览

  [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项,我刚测试下为什么执行呢,什么结果都没有,那我要返回删除后的完整数组应该怎么写?

谢谢大神,试出来了

你打印出来看呀!你主贴中的不是你打印出来的吗?

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn