PHP Switch case Condition and use instance

Source: Internet
Author: User
Tags php switch switch case

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.