Re: returning more than 1 value from function

From: Date: Thu, 04 Jul 2002 17:59:02 +0000
Subject: Re: returning more than 1 value from function
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-105481@lists.php.net to get a copy of this message
Sorry ... busy morning ... I misplaced the & for the reference. They should be on the arguments on the function definiton, not the function call. <?php function test( &$arg1, &$arg2 ){ // Note the "&" before the arguments. $arg1 = "foo"; $arg2 = "bar"; } $var1 = ""; $var2 = ""; test( $var1, $var2 ); ?> Sorry if I caused any confusion. ~Chris /"\ \ / Microsoft Security Specialist: X The moron in Oxymoron. / \ http://www.thebackrow.net On Thu, 4 Jul 2002, Chris Wesley wrote: > On Thu, 4 Jul 2002, andy wrote: > > > i am wondering if it is possible to return more than 1 value from a > > function? > > You can pass your arguments by reference. > > <?php > function test( $arg1, $arg2 ){ > $arg1 = "foo"; > $arg2 = "bar"; > } > > $var1 = ""; > $var2 = ""; > > test( &$var1, &$var2 ); // Note the "&" before the arguments. > ?> > > The result will be that $var1 == "foo" and $var2 == "bar". > > You can mix it up too ... if you want the function to return a value (say, > true or false) AND modify arguments, modify only a subset of the > arguments, etc. > > (see http://www.php.net/manual/en/functions.arguments.php) > > g.luck, > ~Chris /"\ > \ / Microsoft Security Specialist: > X The moron in Oxymoron. > / \ > http://www.thebackrow.net > >

« previous php.general (#105481) next »