At the heart of everything you do, all day long every day, is an if/then conditional.
When you decide to leave the house, this is what your brain does :
If ( $raining == “Yes” ) {
$take_an_umbrella = “Yes”;
} else {
$take_an_umbrella = “No”;
}
Granted the brain is far more complicated, but like the brain, your application will execute these types of statements to process inputs, decide on which functions to execute, and overall allow more then one scenario to occur with your application. Also like your brain, you if/then statements and other conditions will also get more and more complicated, but today we deal with the basics.

If/else VS Switch:
The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.
if($test == “foo”)
// do stuff
else if($test == “bar”)
// do other stuff
else if($test == “foo bar”)
// do other other stuff
else
// do something totally different
switch($test)
{
case “foo”:
// do stuff
break;
case “bar”:
// do other stuff
break;
case “foo bar”:
// do other other stuff
break;
default:
// do something totally different
break;
}
Visit the PHP Manual on operators.
Be sure to subscribe via iTunes and leave us your feedback there as well, we’d love to hear from you! Click here to subscribe!
Enjoy :
Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.