Categories > TinyButStrong general >

help me on recursion function

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: thuc101
Date: 2010-12-21
Time: 02:26

help me on recursion function


<?php
    function recursion($arr){
        printf('<ul>');
        foreach($arr as $item){
            if(is_array($item)){
                recursion($item);
            }
            else printf('<li>%s</li>',$item);
        }
        printf('</ul>');
    }
    function recursion1($arr){
        $st='<ul>';
        foreach($arr as $item){
            if(is_array($item)){
                recursion1($item);
            }
            else
            {
                $st.='<li>'.$item.'</li>';
            }
        }
        $st.='</ul>';
        return $st;
    }
    $a=array('aaa','bbb',array('ccc','ddd'));
    recursion($a);
    //echo recursion1($a);
?>


recursion($a); ---> is work good
but echo recursion1($a); --> is work bad
why???. help me, thank a lot
By: kle_py
Date: 2010-12-21
Time: 16:01

Re: help me on recursion function

try (in recursion1):
...
   if(is_array($item)){
    $st.= recursion1($item);
By: thuc101
Date: 2010-12-23
Time: 04:02

Re: help me on recursion function

hi, thank kle_py
what clever you are!!!
I forget return for function