PHP删除多维数组某个字段的问题

Array ( [id] => 10004

[naem] => 学校

[information] =>

[user] => Array ( [0] => Array 

( [id] => 20001

[name] => lin

[pass] => ybzzax

[age] => 19

[group_id] => 10004

[house] => Array ( [0] => Array

( [id] => 1

[name] => 小明 

[tel] => 2147483647

[user_id] => 20001 ) ) ) 

[1] => Array

([id] => 20002 

[name] => dong

[pass] => ybzzam

[age] => 19

[group_id] => 10004

[house] => Array ( [0] => Array 

( [id] => 2

[name] => 小红

[tel] => 2147483647

[user_id] => 20002 ) ) )

[2] => Array 

( [id] => 20003 

[name] => tian 

[pass] => ybzzan 

[age] => 19

[group_id] => 10004

[house] => Array ( [0] => Array

( [id] => 3

[name] => 小白

[tel] => 2147483647

[user_id] => 20003 ) ) )

[3] => Array ( 

[id] => 20004 

[name] => chi

[pass] => ybzzar

[age] => 19

[group_id] => 10004

[house] => Array ( [0] => Array ( 

[id] => 4 

[name] => 小东

[tel] => 2147483647

[user_id] => 20004 ) ) ) ) )



//$array是返回的数据  $character是要消除的字段
public function dataHandle($array=[],$character=[]){
   foreach ($array as $key=>$arrValue) {
       foreach ($character as $value){
           if (!is_array($arrValue)&&array_key_exists($value,$array)) {
               if($key==$value){
                   unset($array[$key]);
               }
               break;
           }else{
               if(!is_array($arrValue)){
                   continue;
               }else{
                   $this->dataHandle($arrValue,$character);
               }

           }
       }

为什么unset没用

最终还是原来的数据

倔强青铜
浏览 1631回答 1
1回答

万飞

PHP要想在循环中改变数组本来的数据要在$item前面加&
打开App,查看更多内容
随时随地看视频慕课网APP