Source Code:
(back to article)
<?php // Example 1 $myNumber = 5; switch ($myNumber) { case 1: echo "Number is 1"; break; case 2: echo "Number is 2"; break; default: echo "Number is not 1 or 2" . PHP_EOL; break; } // Output: Number is not 1 or 2 // Example 2 $myString = "hello"; switch ($myString) { case "hi": echo "Greeting is hi"; break; case "hello": echo "Greeting is hello"; break; default: echo "Greeting is not recognized"; break; } // Output: Greeting is hello
Result:
Report an issue