RE: [PHP] return value from recursive function

From: Date: Sun, 29 Jul 2001 13:25:08 +0000
Subject: RE: [PHP] return value from recursive function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-60098@lists.php.net to get a copy of this message
maybe it is just me and my preferred syntax/style... if ($i < 4) { abc_recurse(); } return 'xyz'; # NOTICE REMOVED ()'s Did not look to closely at your shortcut symantics to verify legitimacy Also, unless I am mistaken, people generally advise against having a function do output. A more appropriate syntax might be <? function abc_recurse($r) { global $r; static $i = 1; $r.=$i; $i++; if ($i < 4) { abc_recurse($r); } return $r.'xyz'; } $returnvalue = abc_recurse(0); echo $returnvalue; ?> messy but a quick example. >-----Original Message----- >From: Jaskirat [mailto:jaski@satyam.net.in] >Sent: Sunday, July 29, 2001 8:47 PM >To: php-general@lists.php.net >Subject: [PHP] return value from recursive function > > >Hi, >How to get return value from a recursive function .. here is the test code >which I was trying > ><? >function abc_recurse() >{ > static $i = 1; > echo $i; > $i++; > if ($i == 4) return ("xyz"); > abc_recurse(); > >} > >$returnvalue = abc_recurse(); >echo $returnvalue; > >?> >Its printing "123" where as I was expecting "123xyz" >what is happening to $returnvalue > >TIA >Jaski > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net >For additional commands, e-mail: php-general-help@lists.php.net >To contact the list administrators, e-mail: php-list-admin@lists.php.net > > >

« previous php.general (#60098) next »