+ 1
php switch
why the output here is "Working day" in this code : $day = 'Wed'; switch ($day) { case 'Mon': echo 'First day of the week'; break; case 'Tue': case 'Wed': case 'Thu': echo 'Working day'; break; case 'Fri': echo 'Friday!'; break; default: echo 'Weekend!'; } shouldn't here print the default ? because in case "wed" there is nothing ?
5 Answers
+ 15
In a switch statement, you can have multiple cases for a single section of code. In this one, "Working Day" prints for "Tue", "Wed", and "Thu" cases.
The only way for a case to do nothing is to only have break; beneath it.