You are here: recursive function is wrong « PHP Programming Language « IT news, forums, messages
recursive function is wrong

Posted by MrData on 11/08/06 18:39

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_block="")
{
preg_match_all(sprintf($this->s_block,'.*?'),$string,$matches,PREG_SET_ORDER);
foreach ($matches as $match)
{
$temp = array('name' => $match[1]);
if ( preg_match_all(
sprintf($this->s_block,'.*?'),$match[2],$blocks,PREG_SET_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

:(

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация