php switch | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 ?

30th Nov 2017, 3:02 AM
Ali Mikael
Ali Mikael - avatar
1 Answer
+ 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.
30th Nov 2017, 3:10 AM
Tamra - avatar