You are here: Detecting Recursion « PHP Programming Language « IT news, forums, messages
Detecting Recursion

Posted by Thomas Mlynarczyk on 10/18/05 19:58

Hi,

Say I have an array containing a reference to itself:
$myArray = array();
$myArray['self'] =& $myArray;
How can I, looping iteratively through the array, detect the fact that
$myArray['self'] will "take" me to where I have already been? The print_r()
and var_dump() functions print *RECURSION* in such a case (though only after
the "second round"). Setting a flag seems to be the only solution, but I
don't want to modify the array in question - I want to produce a visual
representation of its contents like var_dump(), but formatted to my taste. I
had considered parsing the output of var_dump(), but first, that format
might change in a future version of PHP and second, an array key might be a
string resembling part of the output (like $myArray['["myArray"]=>']), which
seems to be difficult to detect by the parsing code.

Is there another way of doing this?

Greetings,
Thomas

 

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

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