How can you simplify this code? Do it with just one switch.

<?php $day = 1; switch ($day >= 1 && $day <= 5) { case $day: echo "Это рабочий день"; break; } switch ($day >= 6 && $day <= 7) { case $day: echo "Это выходной день"; break; } ?> 
  • Does this code work for you? This is a very strange use of switch. Why not use if( $day >= 1 && $day <= 5 ) { рабочий } else { выходной } - Mike
  • that's just the point that it is necessary to switch - Beginner

2 answers 2

 <?php $day = 1; switch ($day) { case 1: case 2: case 3: case 4: case 5: echo "Это рабочий день"; break; case 6: case 7: echo "Это выходной день"; break; default: echo "Ошибка"; break; }; ?> 
  • for sure! thank! - Beginner
  • MDA simplified ... - Naumov

Only if you are sure that $ day will never be more than 7 and less than 1 (the second, by the way, is much more likely)

 switch($day){ case 6: case 7: echo "Это выходной день"; break; default: echo "Это выходной день"; }