Why does recursion not work? Depressed.

Source: Internet
Author: User
Recursive traversal of PHP

Array ([0] = = Array ([0] = 1 [catid] = 1 [1] = 0 [pa Rentid] + 0 [2] = = About us [catname] = About us [3] = 4 [Listorder] =& Gt 4 [4] = 0 [Items] = 0 [5] = 1 [Type] = 1 [child] =& Gt                            Array ([0] = = Array ([0] = 2 [CATID] + 2 [1] = 1 [parentid] =& Gt  1 [2] = = About us [catname] = About us [3]                            = 1 [Listorder] + 1 [4] = 0             [Items] = 0 [5] = 1 [Type] = 1)       [1] = = Array ([0] = 3 [CATID] = 3 [1] = 1 [parentid] + 1 [2                            ] = [CatName] [Company honors] [3] = 2                            [Listorder] [2] [4] = 0 [Items] = 0 [5] = 1 [type] + 1) [2] = + Ar                            Ray ([0] = 4 [catid] = 4                            [1] = 1 [ParentID] = 1 [2] = = Contact us [CatName] = = Contact us [3] = 3 [Listorder] =& Gt                   3         [4] = 0 [Items] = 0 [5] = 1                            [Type] = 1) [3] = = Array (                            [0] = 5 [CATID] = 5 [1] = 1                            [ParentID] + 1 [2] = + Join us [catname] = Join us [3] = 4 [Listorder] = 4 [4] = = 0 [Items] = 0 [5] = 1 [Type] =&gt ; 1) [4] = = Array ([0] =&gt ; 6 [CATID] = 6 [1] = 1 [ParentID]             = 1               [2] = = Friendship link [catname] = [3] = 5 [Listorder] [5] [4] = 0 [items] = =                0 [5] = 2 [Type] = 2) )        ))

function Gettree ($arr) {//$row = $arr; foreach ($arr as $k + = $v) {$tree. = '
  • '. $v [' CatName ']. "; if (Is_array ($v [' child ')]) {$tree. = '
      ; Traverse the child subarray of foreach ($v [' Children '] as $SV) {$tree. = '
    • '. $sv [' CatName ']. "; Gettree ($v [' child ']); if (Is_array ($sv [' child ')]) {$tree. = '
        ; foreach ($sv [' child '] as $SSV) {$tree. = '
      • '. $SSV [' CatName ']. "
      • "; } $tree. = "
      "; } $tree. = "
    • "; }//print_r ($v [' child ']);//Gettree ($v [' child ']); $tree. = "
    "; } $tree. = '
  • ';} return $tree;}


    Reply to discussion (solution)

    You don't have recursion! Gettree ($v [' child ']); It's all commented out.
    Gettree has a return $tree;
    If recursive, you should write $tree. = Gettree ($v [' child ']);

    You don't have recursion! Gettree ($v [' child ']); It's all commented out.
    Gettree has a return $tree;
    If recursive, you should write $tree. = Gettree ($v [' child ']);

    Thank you very much, commented out, there is no output no way
    Writing $tree. = Gettree ($v [' child ']); Sweat

    I said, thank you.

  • 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.