Switch statement use for check same variable with different values. We use break and default keywords with switch.
This is example of switch.
This is result.
Ok. This is a my change. I replace all colon with semicolon looks like following.
I have found it from php manual.
This is example of switch.
$i = 2; switch ($i) { case 0: case 1: case 2: echo "i is less than 3 but not negative"; break; case 3: echo "i is 3"; break; default: echo 'this is default'; }
This is result.
i is less than 3 but not negative
Ok. This is a my change. I replace all colon with semicolon looks like following.
$i = 2; switch ($i) { case 0; case 1; case 2; echo "i is less than 3 but not negative"; break; case 3; echo "i is 3"; break; default; echo 'this is default'; }Can you guess the result. Check your answer with following.
- Result is same. It will give i is less than 3 but not negative as the result.
- Result is i is 3.
- Result is this is default.
- Result will be notice.
- Result will be warning.
- Result will be fatal error.
I have found it from php manual.