RE: [PHP] Function: return multple values
| From: | Jon Haworth | Date: | Mon, 23 Sep 2002 09:14:11 +0000 |
| Subject: | RE: [PHP] Function: return multple values | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-117251@lists.php.net to get a copy of this message | ||
Hi Faisal,
> Is it possible to return multiple values in a function.
> For instance, i want to do something like this:
>
> function calculate_money($sum)
> {
> // some hanky panky calculations
> return $type;
> return $amount;
> }
You have to return the values in an array, and use list() to break them up.
Try this:
function calculate_money($sum)
{
// do stuff
return array($type, $amount);
}
list($type, $amount) = calculate_money($whatever);
Cheers
Jon