Re: Multiple function return question
| From: | Matt | Date: | Sun, 15 Sep 2002 12:13:11 +0000 |
| Subject: | Re: Multiple function return question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-116434@lists.php.net to get a copy of this message | ||
> From: "Paul Maine" <pmaine@austin.rr.com>
> Sent: Sunday, September 15, 2002 8:10 AM
> Subject: [PHP] Multiple function return question
> I have a function that calls a function that in turns calls the last
> function. I want the last function that is called to return to the
function
> that called it. How do I do this in PHP?
Unless I misunderstand, that is exactly how functions work. Try it:
<?php
function c($var) {
echo "Entering function c: $var<br>\n";
$var += 1;
echo "Leaving function c: $var<br>\n";
return $var;
}
function b($var) {
echo "Entering function b: $var<br>\n";
$var += 1;
$var = c($var);
echo "Leaving function b: $var<br>\n";
return $var;
}
function a($var) {
echo "Entering function a: $var<br>\n";
$var += 1;
$var = b($var);
echo "Leaving function a: $var<br>\n";
$return $var;
}
$i = a(10);
echo "<br>Final value: $i<br>\n";