Re: return value from recursive function
| From: | Rainer Rosenberger | Date: | Sun, 29 Jul 2001 14:21:21 +0000 |
| Subject: | Re: return value from recursive function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-60100@lists.php.net to get a copy of this message | ||
Hi,
your call to abc_recurse returns the return value of the FIRST call. You
forgot to pass the result back to the calling funtions (below corrected
code).
<?php
function abc_recurse($imax) {
static $i=1;
if ($i == $imax) {
return "xyz";
} else {
$i++;
return abc_recurse($imax);
}
}
echo "\n\nFinal Return:" . abc_recurse(4);
?>
Regards
--
Rainer Rosenberger
__________________________________________________________
NetAktiv, Beratung & Realisierung
Dr. Rainer Rosenberger, Fürholzer Weg 6b, D-85375 Neufahrn
Fon:+49 8165 66506, Fax:+49 8165 66507, Mobil:+49 172 7789381
mailto:Rosenberger@NetAktiv.de http://www.NetAktiv.de/
__________________________________________________________
"Jaskirat" <jaski@satyam.net.in> schrieb im Newsbeitrag
news:5.0.0.25.0.20010729174327.01e0a8f0@pop.mail.yahoo.com...
> 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
>