Re: Confused about return
| From: | Rich Cavanaugh | Date: | Wed, 30 Aug 2000 20:31:44 +0000 |
| Subject: | Re: Confused about return | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-14461@lists.php.net to get a copy of this message | ||
Ok, I haven't looked at the Zend site, but just ignore the example you
showed.
<?php
function foo( $x, $y ) {
$a = $x + $y;
$b = $x - $y;
return array($a, $b);
}
$n = 5;
$m = 2;
$test = foo( $n , $m );
echo $test[0];
echo $test[1];
?>
This would output 7 and 3.
I hope this example is a little clearer.
-Rich
"David VanHorn" <dvanhorn@cedar.net> wrote in message
news:4.3.2.7.2.20000830105912.00de9580@mail.cedar.net...
>
> 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
>
>
>
> --
> 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
>