PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hi,
This should be simple for an experience PHP'er. I have a function that I want to provide multpile returns but i'm not too sure how to it i.e
return exits your function, so the second return $var1; doesn't get executed. You'd better create multiple functions to return different values, instead of one function trying to return multiple different things. However, if you need to return some values which are very much of the same type, you can return an array.
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Thanks Ree,
if 'return' exits the function and i have a 'return' in a 'case' within a 'switch' i dont need to break from the case?
ie
function myFunc($fruit)
{
switch($fruit)
{
case 'apple':
$price = 50;
break;
case 'banana':
$price = 40;
break;
...
}
return '$' . (string) $price;
}
You're returning $price everywhere, so why not write it once only? It will also help if you later decide to modify the returned price, for example, convert it to another currency (unlikely, but who knows? ).
Last edited by Ree on Mon Oct 17, 2005 6:21 am, edited 4 times in total.