About PHP submission form array display

 1 <!DOCTYPE html>
 2 <html>
 3 <head>
 4     <title></title>
 5     <meta charset="utf-8">
 6 </head>
 7 <body>
 8     <form action="" method="get">
 9         <select multiple="multiple" name="city[]">
10             <option value= "" > Please select a city </ the Option > 
11              < the Option value = "Beijing" > Beijing </ the Option > 
12              < the Option value = "Shanghai" > Shanghai </ the Option > 
13              < the Option value = "Guangzhou" > Guangzhou < / Option > 
14              < Option value = "Shenzhen" > Shenzhen </ Option > 
15              <the Option value = "Dalian" > Dalian</option>
16         </select>
17         <input type="submit" value="点击">
18      </form>
19      <?php
20        header("Content-Type:text/html;charset=utf-8");
21 
22        $selected=isset($_GET["city"])?$_GET["city"]:"";
23        if(is_array($selected)){
24          foreach($Selected AS $ Key => $ value ) {
 25           echo "City IS" $. value "<br>";.
 26 is        }
 27      }
 28      >? 
explained : where
<select multiple = "multiple" name = "city [] "> attribute is set to multiple, which means can be selected,
the value of name is modified into an array.
The name of the city passed to the selected variables, as selected variable is now an array, it is necessary to use the results of the value of the foreach loop through the array print them all.
29 
30 </body>
31 </html>

 

show result:

 

 

Guess you like

Origin www.cnblogs.com/cute-puli/p/11113236.html