How to correctly implement PHP to get the checkbox value for beginners is still relatively unfamiliar. Here we will give you a detailed introduction of the relevant implementation methods, I hope to help you.
- < input type = "checkbox" name = "weeks[]"
ID="Weeks" value=1>
- < input type = "checkbox" name = "weeks[]"
id = "weeks" value = 2 span class= "tag" > ;
- < input type = "checkbox" name = "weeks[]"
ID="Weeks" 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);
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 span class= "attribute" >type = "checkbox"
name = "t1[]" value = "basketball" > Basketball < br >
- < input type = "checkbox"
name = "t1[]" value = "soccer" > soccer < br >
- < input span class= "attribute" >type = "checkbox"
name = "t1[]" value = "table tennis" > Table Tennis < br >
- < input type="checkbox"
name = "t1[]" value="Volleyball"> Volleyball < BR >
- < input type="Submit">
- < /form >
This is the two ways PHP gets the checkbox value.
http://www.bkjia.com/PHPjc/445960.html www.bkjia.com true http://www.bkjia.com/PHPjc/445960.html techarticle how to correctly implement PHP to get the checkbox value for beginners is still relatively unfamiliar. Here we will give you a detailed introduction of the relevant implementation methods, I hope to help you ...