recursive function is wrong

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MrData

    #1

    recursive function is wrong

    Hi,

    I have a big problem with my recursive function.
    This function have the task to find all blocks in the template file out
    and put it recursive into a array. hierarchy of the blocks are
    important

    At first I try to get all the blocks, but the result is wrong.

    [php]
    function _buildBlocks2($ string,$cur_blo ck="")
    {
    preg_match_all( sprintf($this->s_block,'.*?') ,$string,$match es,PREG_SET_ORD ER);
    foreach ($matches as $match)
    {
    $temp = array('name' =$match[1]);
    if ( preg_match_all(
    sprintf($this->s_block,'.*?') ,$match[2],$blocks,PREG_S ET_ORDER) )
    {
    $temp['children']=array();
    foreach ($blocks as $block)
    $temp['children'][]=$this->_buildBlocks2( $match[2],$block[1]);
    }
    }
    return $temp;
    }
    [/php]

    I looking forward to this result
    Block A
    Block B
    ...||
    ...Block B1.1
    ......|| Block B1.1.1
    ..........|| Block B1.1.1.1
    ..........|| Block B1.1.1.2
    Block C

    But this is my current wrong result
    Block B
    ....||
    ....Block C
    ....Block C

    :(

Working...