As we all know, switch cycle is more than if...else ... The cycle efficiency is much better, when case has the same code structure, how to simplify the code structure, can make the code more universal?
On the internet to find a bit, a lot of copy and paste, and some look too complex, their own research, paste a code for everyone to exchange study, big god please the upper right corner of the!
<?PHP$str=$_get[' I '];Switch($str) { Case0:Echo"Equals 0, output this sentence and jump out of the loop"; Break; Case1 | | 4:Echo"Equals 1 or 4, output this sentence."; if($str==1 && 1 < 2){ //jump out of circulation when conditions are not met Break; } Echo"Continue to output this sentence when conditions are met"; Break; Case2:Echo"Equals 2, the output of this sentence does not jump out of the loop, continue to execute case 3"; Case3:Echo"Equals 3, output this sentence and jump out of the loop"; Break; default:Echo"Default Output"; Break;}?>
Preview Address: Http://localhost/test/switch.php?i=1 (please modify the URL according to your own configuration environment)
If there are errors, please point out!!!
PHP Switch case Condition and use instance