Is it possible to have a function with 2 returns like this:
function test($testvar)
{
// do something
return $var1;
return $var2;
}
If so, how would I be able to get each return separately?
Is it possible to have a function with 2 returns like this:
function test($testvar)
{
// do something
return $var1;
return $var2;
}
If so, how would I be able to get each return separately?
There is no way of returning 2 variables. Although, you can propagate an array and return it; create a conditional to return a dynamic variable, etc.
For instance, this function would return
$var2
In application:
If you wanted them both, you could modify the function a bit
The answer is no. When the parser reaches the first return statement, it will direct control back to the calling function - your second return statement will never be executed.
Or you can pass by reference:
This would output
Its not possible have two return statement. However it doesn't throw error but when function is called you will receive only first return statement value. We can use return of array to get multiple values in return. For Example:
This is the easiest way to it
How to call this function?
That's it, very rasy