本帖最后由 baidu_27153093 于 2015-05-06 11:31:40 编辑
<br /><br />Array<br />(<br /> [0] => Array<br /> (<br /> [id] => 3<br /> [fid] => 0<br /> [name] => 333<br /> [son] => Array<br /> (<br /> [0] => Array<br /> (<br /> [id] => 2<br /> [fid] => 3<br /> [name] => 2_3<br /> [son] => Array<br /> (<br /> [0] => Array<br /> (<br /> [id] => 4<br /> [fid] => 2<br /> [name] => 2_4<br /> )<br /><br /> )<br /><br /> )<br /><br /> [1] => Array<br /> (<br /> [id] => 5<br /> [fid] => 3<br /> [name] => 2_3<br /> )<br /><br /> )<br /><br /> )<br /><br /> [1] => Array<br /> (<br /> [id] => 1<br /> [fid] => 0<br /> [name] => 111<br /> )<br /><br />)
这是一个tree结构的数组,我希望在每个数组元素上加一个层级元素;
<br />function tree_add_level($tree){<br /> foreach($tree as &$val){<br /> if(!isset($val['_level'])){<br /> $val['_level']=0;//顶层为0<br /> }<br /> if(isset($val['son'])){<br /> $val['son']['_level']=$val['_level']+1; //下级加1<br /> tree_add_level($val['son']);<br /> }<br /> }<br /> return $tree;<br />}<br /><br /><br />
但是却提示语法错误,求解决方法,或者其他方式. 谢谢
------解决思路----------------------你这个数组能粘贴出来吗,我测试一下