recursive function is wrong

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!


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

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

function _buildBlocks2($string,$cur_block="")
    foreach ($matches as $match)
        $temp = array('name' => $match[1]);
        if ( preg_match_all(
sprintf($this->s_block,'.*?'),$match[2],$blocks,PREG_SET_ORDER) )
            foreach ($blocks as $block)
    return $temp;

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


Site Timeline