@andrewvpover you need the return statement at each of the case statements because once the processor hits the break; it exits the switch statement, so it doesn't process any more code within the switch.
Hope you know you can set the return once just return the total after the switch statement and have a if statement that only if total isn't in error or blank or null then return $total. that be more efficient way of doing it.
Don't mean to spam but I know you guys will be interested. We (Appetude.com) are giving away $1000 to the first person to REFER a PHP developer to us that we hire! We are in NY, NY. Send contact information of the developer to hire@appetude.com.
thank you Alex, i have been watching your video for a while how. and every time that i watch a video i actually learn something. i really enjoyed that jquery refresh tutorial.
hello alex, great tut... I am working through dreamweaver....I discovered that the RETURN function do not work instead it was ECHO function...why is that?
@mega3a4ot if you do it like this you need to declare default as $total = "unknown operator.", or you will get an unknown variable error because there is no $total in default
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 "": } .
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.
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.
@olie04 NO you cannot use return to echo, if you like just to echo it out then you will need to do echo(1,5,"+"); in the function for each switch case.
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!)
if it goes to default, it'll be smth like echo echo "Unknown opreator.";
You could have given the variable $total = "Unknown operator"; and just return it at the end of the function. Nice video, btw! :)
sergyu123456 2 months ago
Comment removed
andrewvpover 3 months ago
@andrewvpover you need the return statement at each of the case statements because once the processor hits the break; it exits the switch statement, so it doesn't process any more code within the switch.
i3oges 2 months ago
Hope you know you can set the return once just return the total after the switch statement and have a if statement that only if total isn't in error or blank or null then return $total. that be more efficient way of doing it.
shyhockeyboy 4 months ago
it's important to have in mind
$num2 must be different than 0 in case of division.
riotofdablood 5 months ago
it's important to have in mind
$num2 must be different than 0 in case "/" :
riotofdablood 5 months ago
Beautiful
Bramborail 7 months ago
This has been flagged as spam show
Don't mean to spam but I know you guys will be interested. We (Appetude.com) are giving away $1000 to the first person to REFER a PHP developer to us that we hire! We are in NY, NY. Send contact information of the developer to hire@appetude.com.
MrMarkalayev 8 months ago
thank you Alex, i have been watching your video for a while how. and every time that i watch a video i actually learn something. i really enjoyed that jquery refresh tutorial.
liquidphp 11 months ago
no need to break after a return...
slickrtm 1 year ago
hello alex, great tut... I am working through dreamweaver....I discovered that the RETURN function do not work instead it was ECHO function...why is that?
kollyajax 1 year ago
One question, why do you do "$" before num ?
VisualIlusion 1 year ago
@VisualIlusion watch his previous videos...
sk8erdan95 1 year ago
@VisualIlusion The sign $ is required for PHP variables.
Medo3337 11 months ago
@Medo3337 Thanks and, where'd you learn all this?
VisualIlusion 11 months ago
@VisualIlusion There are alot of resources, you can check PHP official website.
Medo3337 11 months ago
@VisualIlusion w3schools. google it
jaradgrant1 9 months ago
@jaradgrant1 Thanks man!
VisualIlusion 9 months ago
@VisualIlusion most php programmers are home tought, just google php tutorials
madmatthew1 7 months ago
@madmatthew1 Thanks!
VisualIlusion 7 months ago
Larry Ullman says that you can RETURN $variable too, but what is the $variable?
TomHobbes 1 year ago
In this tut Alex contains with functions and how to declare a function which return a numerical/string value .
elcrimer 1 year ago 4
This isn't secure, but it does the same job :-)
function calc($num1,$num2,$op){ return eval("return $num1$op$num2;");
}
daveashe 1 year ago
It's alright but why do you return $total 4 times instead of using it once in the end of the function?
mega3a4ot 2 years ago 7
@mega3a4ot if you do it like this you need to declare default as $total = "unknown operator.", or you will get an unknown variable error because there is no $total in default
iTwistar 11 months ago
@mega3a4ot because if you return it at the end of the the function if you have an unknown operator then you will have an error.
mikekevinvideos 7 months ago
@mikekevinvideos
Not if you check that the value of the $total variable isset.. You should be checking the value before returning it, anyway.
therealnod 6 months ago
@mega3a4ot That what I wanted to say when I saw it.
Bramborail 7 months ago
What is the difference in using the "switch" and "case" statements and using if else statements?
gigman7 2 years ago
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 "": } .
DrWestofReanimation 2 years ago
You've lost me. I'm not sure I understand the advantage of using one over the other.
gigman7 2 years ago
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.
DrWestofReanimation 2 years ago
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.
labandus 2 years ago
Can RETURN be substituted by ECHO in functions? or does it have to be RETURN all the time in functions.
olie04 2 years ago 2
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.
phpacademy 2 years ago 2
@olie04 NO you cannot use return to echo, if you like just to echo it out then you will need to do echo(1,5,"+"); in the function for each switch case.
dhelled1 1 year ago
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!)
chjustin69 2 years ago
Oh cool, the return command is pretty neat! Now you can only return one value to the function right?
chjustin69 2 years ago