Maison >développement back-end >tutoriel php >请问这段代码到底什么问题? 为什么会报错;
Array( [0] => Array ( [id] => 3 [fid] => 0 [name] => 333 [son] => Array ( [0] => Array ( [id] => 2 [fid] => 3 [name] => 2_3 [son] => Array ( [0] => Array ( [id] => 4 [fid] => 2 [name] => 2_4 ) ) ) [1] => Array ( [id] => 5 [fid] => 3 [name] => 2_3 ) ) ) [1] => Array ( [id] => 1 [fid] => 0 [name] => 111 ))
function tree_add_level($tree){ foreach($tree as &$val){ if(!isset($val['_level'])){ $val['_level']=0;//顶层为0 } if(isset($val['son'])){ $val['son']['_level']=$val['_level']+1; //下级加1 tree_add_level($val['son']); } } return $tree;}
提示: Warning: Cannot use a scalar value as an array in D:\Web\BOOT\newfile.php on line 28
tree_add_level($val['son']); 这句代码到底有什么问题? 递归下而已.
你需要判断一下$tree是否是数组
你需要判断一下$tree是否是数组
你这个数组能粘贴出来吗,我测试一下
你需要判断一下$tree是否是数组
你这个数组能粘贴出来吗,我测试一下
警告其实不影响,只要你得到了你想要的结果