What is the problem with this code? Why is an error reported? This post was last edited by baidu_27153093 from 2015-05-0611: 31: 40 Array (& nbsp; [0] & nbsp; & gt; & nbsp; Array & nbsp; & what is the problem with this code? Why is an error reported;
This post was last edited by baidu_27153093 at 11:31:40 on
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
)
)
This is an array of tree structures. I want to add a hierarchical element to each array element;
Function tree_add_level ($ tree ){
Foreach ($ tree as & $ val ){
If (! Isset ($ val ['_ level']) {
$ Val ['_ level'] = 0; // The top layer is 0.
}
If (isset ($ val ['son']) {
$ Val ['son'] ['_ level'] = $ val [' _ level'] + 1; // add 1 to the lower level
Tree_add_level ($ val ['son']);
}
}
Return $ tree;
}
However, a syntax error is Prompted. find a solution or another method. thank you.
------ Solution ----------------------
Can you paste this array? let me test it.