Home  >  Article  >  Backend Development  >  请教这段代码到底什么有关问题? 为什么会报错

请教这段代码到底什么有关问题? 为什么会报错

WBOY
WBOYOriginal
2016-06-13 12:19:17859browse

请问这段代码到底什么问题? 为什么会报错;

本帖最后由 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 />


但是却提示语法错误,求解决方法,或者其他方式. 谢谢
------解决思路----------------------
你这个数组能粘贴出来吗,我测试一下
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:关于U 步骤Next article:请问个伪静态的有关问题