June 7, 2010

How to add multiple condition cases inside Switch method?

Question by Starx

Is there a way to include multiple cases inside a switch method in php?

Answer by Starx

Yes it is possible

Here is an example to start with

<?
      $i = 1;
      $j = 10;

      switch($i) {
            case "2":
                   echo "The value is 2";
                   break;
            case ($i==1 && $j==10):
                   echo "Your exceptional Switch case is triggered";
                   break;
            default:
                   echo "Invalid";
                   break;
     }
?>

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!