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?
I think eliego has explained the answer clearly. But if you want to return both values, put them into a array and return it.
//to access return values
Best Practice is to put your returned variables into array and then use
list()
to assign array values to variables.I have implement like this for multiple return value PHP function. be nice with your code. thank you.
yes, you can use an object :-)
but the simplest way is to return an array:
Some might prefer returning multiple values as object:
And call it like this:
Or:
I know that I am pretty late, but there is a nice and simple solution for this problem.
It's possible to return multiple values at once using destructuring.
Now you can use this
extract
creates a variable for each member in the array, named after that member. You can therefore now access$model
and$data