On Mon, Feb 12, 2001 at 09:13:09PM -0000, James, Yz wrote:
> 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;
You're on the right track.
return Array($var1,$var2);
And when you call the function,
list($ret1,$ret2) = myfunc(); ..or..
$ret = myfunc(); ..and use $ret[0] and $ret[1]
Another option is to pass variables by reference. For example, say you had
a function that returned true or false, but you wanted it to return an error
message with that false. Something like this:
function test($condition,&$errormsg)
{
if ($condition == $rightanswer)
{
return true;
}
else
{
$errormsg = "The condition wasn't the right answer.";
return false;
}
}
Then to check it,
if (!test('foo',$error))
echo "Failed test!<br>Error: $errormsg<br>";
HTH,
Matt
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]