- < input type="checkbox" name="weeks[]"
id="Weeks" value=1>
- < input type = name = "weeks[]"
id = value = 2 >
- < input type = "checkbox" name = "weeks[]"
id = value = 3 >
Weeks after the middle bracket is not leaky, otherwise you can only fetch the last value when you get it in PHP. After that, PHP is very well handled, as follows:
PHP Gets the checkbox value method one:
- $weeks = $_post[' weeks '];
- For ($i=0; $i< count
($weeks); $i + +)
- echo $weeks [1]. " < br> ";
PHP Gets the checkbox value method two:
- $Array = $this->request->
GetParameter ("weeks[]");
- $str =implode (', ', $array);
- Echo $str;
Use the form frequently, where the check box is used frequently. However, unlike other scripting languages in PHP, the name of the check box must be appended with [] and then used as 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="soccer"> Soccer < br>
- < input type="checkbox"
Name="t1[]" value="ping-pong"> Table Tennis < br>
- < input type="checkbox"
Name="t1[" " value=" Volleyball> Volleyball < br>
- < input type="Submit">
- </form>
How to get the values of multiple checkboxes in PHP