What are the issues with this code? Why is an error reported?-php Tutorial

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.