PHP Determines if check box checkbox is selected

Source: Internet
Author: User
Tags mysql tutorial php server php form php tutorial

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:

    1. PHP form submission How to get the value of check box checkbox
    2. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.