Skip to content

Instantly share code, notes, and snippets.

@ksnider
Created January 9, 2014 20:26
Show Gist options
  • Select an option

  • Save ksnider/8341365 to your computer and use it in GitHub Desktop.

Select an option

Save ksnider/8341365 to your computer and use it in GitHub Desktop.
<?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