Re: returning multiple variables from a function?

From: Date: Tue, 13 Feb 2001 06:17:27 +0000
Subject: Re: returning multiple variables from a function?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-39363@lists.php.net to get a copy of this message
there are two ways of achieving this 1. Pass the arguments by reference and you will have their latest values after the function call. look up the manual http://www.php.net/manual/en/language.references.php 2. Create an array in the function with the various values to be returned stored as its elements and then return the array. The array will then have multiple return values in its elements after the function is called. hope that helps regards Ankur Verma HCL Technologies A1CD, Sec -16 Noida, UP India ----- Original Message ----- From: "James, Yz" <liljim@btconnect.com> To: <php-general@lists.php.net> Sent: Tuesday, February 13, 2001 2:43 AM Subject: [PHP] returning multiple variables from a function? > Hrms. Got a small problem. > > I'm now using functions on a regular basis, but I've come to another > sticking point with them: returning multiple variables from the function... > > Here's a really quick example (nothing to do with what I intend to use the > functions for): > > function CUP ($connection,$username,$password) { > > if (($username) && ($password)) { > $sql = "SELECT username, password FROM table > WHERE username = '$username' AND password = '$password'"; > $result = etc etc > $num = mysql_numrows($result); > > if ($num != 0) { > $valid = "yes"; > } > > return $valid; > > } > > > > $correct_user = CUP ($connection,$username,$password); > > Now, if the user is correct, I'd get a return of > > $correct_user = "yes"; > > What if I wanted to "return" more than one variable from the function? And > how would I assign it a name? Like the actual variable, or is that just not > possible? > > I've tried > return $var1,$var2; > But got an error. > > As always, tia :) > > James. > > > > -- > 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

« previous php.general (#39363) next »