In my last post I’ve talked about variables and operators. Now, lets see what can we do with them.
Statement: if
The “if” statement has 3 main forms:
$name = "José Cruz"; $even = 10 % 2; $odd = 10 % 3; $someValue = $even * 4; $ifvar = 1; // it’s even – simple "if" if($even == 0) { echo "10 its even!"; } // it’s even – simple "if" with an else |
Statement: switch
“switch” it’s a variation of “if”, but for cases where we have some kind of a list of values belonging to a common domain, like: weekdays, months, (1,3,4,5), etc.
The expression inside “switch(
If a “case
$weekday = 1; // assuming a week starts on sunday with value 1 switch($weekday) { case 1: echo "Sunday"; break; case 2: echo "Monday"; break; case 3: echo "Tuesday"; break; case 4: echo "Wednesday"; break; case 5: echo "Thursday"; break; case 6: echo "Friday"; break; case 7: echo "Saturday"; break; default: echo "big mistake1"; } ?> |
And that’s it!
Next post about loops!
Technorati Tags: programming,else,switch,if,php,Statements,expression,break
Windows Live Tags: programming,else,switch,if,php,Statements,expression,break
WordPress Tags: programming,else,switch,if,php,Statements,expression,break