RE: [PHP] Recursion: Ugh!

From: Date: Thu, 26 May 2005 18:53:45 +0000
Subject: RE: [PHP] Recursion: Ugh!
Groups: php.general 
Request: Send a blank email to php-general+get-215840@lists.php.net to get a copy of this message
Marek Kilimajer <mailto:lists@kilimajer.net> on Thursday, May 26, 2005 11:35 AM said: > untested: > > function display($array, $prefix = '') { > echo $prefix ':' . $array['name'] . "\n"; > if(is_array($array['children']) && $array['children']) { > foreach($array['children'] as $child) { > display($child, $prefix ':' . $array['name']); > } > } > } Thanks Marek. I've had one suggestion off list also and, although I haven't been able to test this myself, I think my major mistake is that I've been doing the foreach() BEFORE checking for the existence of an array. Whereas both suggestions so far are checking for the existence of an array before the foreach(). I'll report back to the list with my results. Probably tomorrow. Thanks, Chris.

« previous php.general (#215840) next »