Re: More than one values returned?
| From: | Steve Edberg | Date: | Tue, 19 Feb 2008 23:23:46 +0000 |
| Subject: | Re: More than one values returned? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-269660@lists.php.net to get a copy of this message | ||
At 4:57 PM -0600 2/19/08, Greg Donald wrote:
On 2/18/08, Nick Stinemates <nick@stinemates.org> wrote:For completeness sake, this is pretty much the same in PHP: function test() {I have found, however, that if I ever need to return /multiple/ values, it's usually because of bad design and/or the lack of proper encapsulation.Yeah, that's probably why most popular scripting languages support it. In Ruby: def foo 1, 2 end a, b = foo In Python: def foo return 1, 2 a, b = foo In Perl: sub foo { return (1, 2); } (my $a, my $b) = foo;
return array(1,2);} list($a,$b) = test(); works as above. Works fine with complex arrays as well: function test() {
return array(1,array('a','b'));
}
list($a,$b) = test();
steve
--
+--------------- my people are the people of the dessert, ---------------+
| Steve Edberg http://pgfsun.ucdavis.edu/ |
| UC Davis Genome Center sbedberg@ucdavis.edu |
| Bioinformatics programming/database/sysadmin (530)754-9127 |
+---------------- said t e lawrence, picking up his fork ----------------+