Confused about return
| From: | David VanHorn | Date: | Wed, 30 Aug 2000 16:16:48 +0000 |
| Subject: | Confused about return | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14423@lists.php.net to get a copy of this message | ||
I'm confused over using the return function to return multiple values with an array.
From the Zend site, I get this example..
In a function, you can return multiple variables only by returning an array:
function foo($x,$y) {
$a = $x+$y;
$b = $x-$y;
return array($a, $b, 1);
}
list($sum, $sub) = foo(5, 2, 1);
The way I read this, they are calling the function "foo" with three variables, when it only needs/wants two., and I don't see where the output of the "foo" function is ever presented...
I would have expected something like
$x=10;
$y=20;
foo($x,$y);
followed by something that pulls up the returned values $a and $b, and the passed static value of "1"
Apparently, $sum becomes $x in the function, and $sub becomes $y, but the rest of that line still confuses me, and I dont see how to get at the passed result.
BTW: If 5 is supposed to be $a and 2 is supposed to be $b, what the hell was the input?
3.5 and 1.5 are the only pair I could come up with that satisfy that equality, but where did they enter this example.
Given that examples are supposed to make things clearer to people who don't understand, I'd give this one, an F-.
--
Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9