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.
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 “”: } .
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.
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!)
Why use the return every time in a case, It’s easier to use it outside the switch element.
It’s alright but why do you return $total 4 times instead of using it once in the end of the function?
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.
You’ve lost me. I’m not sure I understand the advantage of using one over the other.
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 “”: } .
What is the difference in using the “switch” and “case” statements and using if else statements?
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.
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.
Can RETURN be substituted by ECHO in functions? or does it have to be RETURN all the time in functions.
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!)
Oh cool, the return command is pretty neat! Now you can only return one value to the function right?