Checkbox checkbox is usually used for php form submission. This article uses examples to introduce to you how to judge whether the value in the check box is selected. Friends who need it can refer to the examples in this article.
This article introduces you two knowledge points:
How to get the value of checkbox checkbox in form submission
How to determine whether the value in the checkbox checkbox is selected
Let’s explain these two knowledge points below:
1. How to get the value of checkbox in php
First, let's create a form:
<form action ="" method="post"> <ul> <li><input type ="checkbox" name ="category[]" value ="php">phpTutorial</li> <li><input type ="checkbox" name ="category[]" value ="java">javaTutorial</li> <li><input type ="checkbox" name ="category[]" value ="mysql">mysqlTutorial</li> <li><input type ="checkbox" name ="category[]" value ="html">htmlTutorial</li> </ul> <input type ="submit"> </form>
Have you noticed that all checkbox name attributes are category[], so why should I set it like this? This is set because we use all checkbox checkbox checkboxes as a group. On the php server side, you can use $_POST['category'] to get the values of all selected checkboxes.
The code for obtaining the checkbox checkbox value on the php server is as follows:
<?php $checkbox_select=$_POST["category"]; print_r($checkbox_select); ?>
Here the $checkbox_select variable is an array. For example, when we select "php tutorial" and "java tutorial", the value of $checkbox_select is as follows:
Array( [0]='php' [1]='java' )
2. How to determine whether the value in the checkbox checkbox is selected
If you know how to get the value of the checkbox checkbox, it will be very simple to determine whether the value in the checkbox checkbox is selected. We only need to traverse the variable $checkbox_select to get which values of the checkbox are selected.
<?php $checkbox_select=$_POST["category"]; for($i=0;$i<count($checkbox_select);$i++) { echo "Options".$checkbox_select[$i]."Selected<br />"; } ?>
The above is the detailed content of the method to determine whether the check box is selected by php. If you have any additional content, please contact me.