<Input type = "checkbox" name = "weeks []" id = "weeks" value = 1> <input type = "checkbox" name = "weeks []" id =" weeks "value = 2> <input type =" checkbox "name =" weeks [] "id =" weeks "value = 3>
The brackets after weeks cannot be left blank. Otherwise, you can only get the last value when using PHP. PHP will handle the problem as follows:
Method 1:
$ Weeks=$ _ Post['Dones'];For($ I= 0;$ I<Count($ Weeks);$ I++)Echo $ Weeks[$ I]. "<Br> ";
Method 2:
$ Array=$ This-> Request-> getparameter ("weeks []");$ Str=Implode(',',$ Array);Echo $ Str;
Forms are frequently used, and check boxes are frequently used. But in PHP, unlike other scripting languages, the name of the check box must be followed by [], and then obtained through an array loop.
<? PHP If (! Empty ( $ _ Post ["T1" ]) { $ Array = $ _ Post ["T1" ]; $ Size = Count ( $ Array ); For ( $ I = 0; $ I < $ Size ; $ I ++ ){ Echo $ Array [ $ I ]. "<Br>" ;}} ?> <Form method = post action = "" name = "form1"> <input type = "checkbox" name = "T1 []" value = "basketball"> basketball <br> <input type = "checkbox" name = "T1 []" value = ""> football <br> <input type = "checkbox" name = "T1 []" value =" table Tennis "> Table Tennis <br> <input type =" checkbox "name =" T1 [] "value =" Volleyball "> volleyball <br> <input type =" Submit "> </form>