Categorized | PHP

PHP Basics: Advanced function

Posted on 07 March 2010 by Abidoon


Not the trickiest example function, however this will teach you how to output a value created from within the function.

Tags | , ,

11 Responses to “PHP Basics: Advanced function”

  1. nielswii says:

    Why use the return every time in a case, It’s easier to use it outside the switch element.

  2. mega3a4ot says:

    It’s alright but why do you return $total 4 times instead of using it once in the end of the function?

  3. DrWestofReanimation says:

    Ideally* -not all, feels like it matter which one should be use-, programmer should use switch-case if he/she have more questions for the end-user to make;such as, menu-base feature, and If/else statements need to use when simple decisions or data control for your program.

  4. gigman7 says:

    You’ve lost me. I’m not sure I understand the advantage of using one over the other.

  5. DrWestofReanimation says:

    If -n-else statements are mostly for control statements, switch statements are using mutiple decision statements for a user can select from. Case is specifing the condition you are chosing. You can say case or switch statement, but you have to speific switch() { case “”: } .

  6. gigman7 says:

    What is the difference in using the “switch” and “case” statements and using if else statements?

  7. labandus says:

    is not possible to define right $total in the function, and then in each “case” of switch, give the value of the choosen operationen.

    At the end we just “return $total” at the end of the function.

    This can spare us define a new “$total” variable in each case.

  8. phpacademy says:

    Yes, you can echo it out directly from inside a function.However it’s better to leave it as a RETURN and then echo it out as you require. Reason being you might want to use the function to do something else later on (i.e. string length) so in this case having it ECHO out as standard won’t work.

  9. olie04 says:

    Can RETURN be substituted by ECHO in functions? or does it have to be RETURN all the time in functions.

  10. chjustin69 says:

    If your like me and like to write a little code after each tut than a “challenge” you can do is to write a calc with all the same functions as above but with less code (you can do it with what we have learned so far!)

  11. chjustin69 says:

    Oh cool, the return command is pretty neat! Now you can only return one value to the function right?


Leave a Reply