Posted By

valcartei on 07/18/07


Tagged

switch-case


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

basicmagic


multiple cases for switch construct


 / Published in: PHP
 

URL: http://www.nutt.net/2004/12/28/multiple-cases-for-switch-construct/

put case value1:case value2:case value3: to allow the same code be executed when the value passed equals value1 or value2 or value3.

  1. switch (value)
  2.  
  3. {
  4.  
  5. case 1:
  6.  
  7. echo "Value was 1";
  8.  
  9. break;
  10.  
  11. case 2:
  12.  
  13. case 3:
  14.  
  15. echo "Value was 2 or 3";
  16.  
  17. break;
  18.  
  19. case 4:
  20.  
  21. echo "Value was 4";
  22.  
  23. break;
  24.  
  25. default:
  26.  
  27. echo "Value was not 1-4";
  28.  
  29. break;
  30.  
  31. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Wardy on November 5, 2008

Multiple cases can also be represented as:

case 1 || 2:echo “foobar”;

You need to login to post a comment.