Advertisement
shuvocse

switch case

Aug 31st, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.54 KB | None | 0 0
  1. <?php
  2.  
  3. $n = 13;
  4. $r = $n % 2;
  5.  
  6. switch ($r) {
  7.     case 0:
  8.         echo "{$n} is an even number";
  9.         break;
  10.    
  11.     default:
  12.         echo "{$n} is an odd number";
  13. }
  14.  
  15. echo "<br/>";
  16.  
  17. $color = 'red';
  18.  
  19. switch ($color) {
  20.     /*case 'red':
  21.         echo "{$color} i like this color";
  22.         break;
  23.     case 'green':
  24.         echo "{$color} i also like this color";
  25.         break;*/
  26.  
  27.     case 'red':
  28.     case 'green':
  29.         echo ucwords($color)."is also like this color";
  30.         break;
  31.     case 'blue':
  32.         echo "{$color} is dont like this color";
  33.         break;
  34.     default:
  35.         echo "this color is ok";
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement