Use the switch statement to judge multiple choices.

Source: Internet
Author: User

1<!doctype html>2<meta http-equiv= "Content-type" content= "text/html" charset= "Utf-8"/>3Switch statement, the switch statement is used to perform different actions based on several different conditions. <br/>4 If you want to selectively execute one of several blocks of code, also use a switch statement. 5<br/>6 The syntax structure is as follows:7<pre>8 Switch(n)9 {Ten  CaseLabel1: Onesuch as n=Label1, here the code will be executed; A      Break; -  CaseLabel2: -such as n=Label2, here the code will be executed; the      Break; -  CaseLABEL3: -such as n=Label3, here the code will be executed; -      Break; + default: - if n does not equal the Label1 page is not equal to Label2, the code here will execute; + } A</pre> at - We write a program, a radio box. Use the switch statement half paragraph.  -<br/> - The procedure is as follows: -<br/> -<form method= "Get" action= "<?php Echo$_server[' php_self '];? > "> inRed: <input type= "Radio" name= "Color" value= "1"/><br/> -Blue: <input type= "Radio" name= "Color" value= "2"/><br/> toGreen: <input type= "Radio" name= "Color" value= "3"/><br/> +<input type= "Submit"/> -</form> the<?PHP * if(!Empty($_get[' Color '])){ $ Switch($_get[' Color '])Panax Notoginseng { -  Case1: the   Echo"Your choice is red!" ";  +    Break; A  Case2: the   Echo"You chose the blue!" "; +    Break; -  Case3: $   Echo"Your choice is green!" "; $    Break; - default: -  Echo"You have not chosen any one color!" "; the } - }Wuyi?>
Code Case

Submit data from the form, accept and submit it by get, and then use empty to determine if the accepted data is empty. Then perform the If judgment to execute the switch statement, you can do a multi-select operation!

Use the switch statement to judge multiple choices.

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.