PHP check box checkbox is checked check box is often used in PHP form submission, this article through an example of how PHP to determine whether the value of check box checkbox is selected, the need for friends can refer to the example of this article.
This article introduces you to two points of knowledge:
- PHP form submission How to get the value of check box checkbox
- How PHP determines if the value in a check box checkbox is selected
Here we explain the two points of knowledge separately:
1. How PHP Gets the value of check box checkbox
Let's start by creating a form:
<FormAction ="Handleformcheckbox.php"Method="POST" ><Ul><Li><InputType ="checkbox"Name ="Category[]"Value ="PHP" >php tutorial</Li><Li><InputType ="checkbox"Name ="Category[]"Value ="Java" >java tutorial</Li><Li><InputType ="checkbox"Name = "category[]" value = "MySQL" > MySQL tutorial </li> < li><input type = "checkbox" name = "category[" "value =" html ">html tutorial Span class= "Hljs-tag" ></li></ Ul><input type =" submit "></FORM>
Did anyone notice that the Name property of all the checkboxes is category[], and why is this set? This is set because we have all CheckBox checkboxes as a group, and the PHP server can use $_post[' category ' to get the values of all checked checkboxes.
The code for the CheckBox check box value for the PHP server side is as follows:
<?php$checkbox_select=$_POST["category"];print_r($checkbox_select);?>
Here the $checkbox_select variable is an array, such as when we select "PHP tutorial" and "Java Tutorial", the values of the $checkbox _select are as follows:
Array( [0]=‘php‘ [1]=‘java‘ )
2. How PHP determines if the value in the CheckBox check box is selected
Knowing how PHP gets the value of the CheckBox checkbox, it would be very easy to determine if the value in the Checkboxes checkbox is selected, and we just need to iterate over the variable $checkbox_select to get what values in the checkbox are selected.
<?php$checkbox_select=$_POST["category"];for($i=0;$i<count($checkbox_select);$i++){echo "选项".$checkbox_select[$i]."被选中<br />";}?>
The above is the entire class of this article, I hope that everyone's study has helped
PHP Determines if check box checkbox is selected