为什么我不能在关联数组php中取消设置数组

时间:2018-04-03 10:56:58

标签: php arrays laravel unset

为什么我不能在关联数组php中取消设置数组 我看到了转储,但我也看到了最终数组中的未经加工的数组

foreach($dossier['program'] as $program){
    foreach($program['cities'] as $city){
        foreach($city['services'] as $service){
            foreach($service['featureds'] as $key=>$featured){
                dump($key);
                if($key!==(int)$quotation_conditions['groups']){
                    dump($service['featureds'][(string)$key]);
                    unset($service['featureds'][(string)$key]);
                }
            }
        }
    }
}
dd($dossier);

1 个答案:

答案 0 :(得分:2)

试试这个

foreach($dossier['program'] as &$program){
    foreach($program['cities'] as &$city){
        foreach($city['services'] as &$service){
            foreach($service['featureds'] as $key=>$featured){
                dump($key);
                if($key!==(int)$dossier['groups']){
                    dump($service['featureds'][(string)$key]);
                    unset($service['featureds'][(string)$key]);
                }
            }
        }
    }
}