为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
倔强青铜 2018-03-31 20:47:54
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没用最终还是原来的数据
查看完整描述

1 回答

?
万飞

TA贡献117条经验 获得超186个赞

PHP要想在循环中改变数组本来的数据要在$item前面加&

查看完整回答
反对 回复 2018-04-01
  • 1 回答
  • 0 关注
  • 1630 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信