Re: More than one values returned?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 4:57 PM -0600 2/19/08, Greg Donald wrote:
On 2/18/08, Nick Stinemates <nick@xxxxxxxxxxxxxx> wrote:
 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;


For completeness sake, this is pretty much the same in PHP:

   function test() {
      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@xxxxxxxxxxx |
| Bioinformatics programming/database/sysadmin             (530)754-9127 |
+---------------- said t e lawrence, picking up his fork ----------------+

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux