Created
January 9, 2014 20:26
-
-
Save ksnider/8341365 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Nested If statements | |
| If($breed == 'dog' ) { | |
| echo 'This is a canine'; | |
| } else { | |
| If($breed == 'horse') { | |
| echo 'This is an equine'; | |
| } else { | |
| echo 'We are not sure what you are'; | |
| } | |
| } | |
| // Imagine how messy this would be if we had 3, 5, or even 20 conditions to test for? | |
| // So instead, we use Switch() | |
| switch ($breed) { | |
| case 'dog': | |
| echo 'This is a canine'; | |
| break; | |
| case 'horse': | |
| echo 'This is an equine'; | |
| break; | |
| case 'cat': | |
| echo 'This is a feline'; | |
| break; | |
| case 'owner': | |
| echo 'This is a human'; | |
| break; | |
| case default: | |
| echo 'We are not sure what you are'; | |
| break; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment