Explore PHP Get checkbox value _php Tutorial

Source: Internet
Author: User
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.

  1. < input type = "checkbox" name = "weeks[]"
    ID="Weeks" value=1>
  2. < input type = "checkbox" name = "weeks[]"
    id = "weeks" value = 2 span class= "tag" > ;
  3. < 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:

 
  
  
  1. $ weeks = $_post[' weeks '];
  2. For ($i=0; $i<Count
    ($weeks); $i + +)
  3. echo $weeks [1]. " < br>";

PHP Gets the checkbox value method two:

 
  
  
  1. $ Array = $this- > request- >
    GetParameter ("weeks[]");
  2. $ 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.

 
 
  1. < ? PHP
  2. if (!empty ($_post["T1")) {
  3. $ Array = $_post["T1"];
  4. $ size = Count ($array);
  5. For ($i=0; $i< $size; $i + +) {
  6. echo $array [$i]. " < br>";
  7. }
  8. }
  9. ?>
  10. < form method = post action = "" name = "Form1" >
  11. < input span class= "attribute" >type = "checkbox"
    name = "t1[]" value = "basketball" > Basketball < br >
  12. < input type = "checkbox"
    name = "t1[]" value = "soccer" > soccer < br >
  13. < input span class= "attribute" >type = "checkbox"
    name = "t1[]" value = "table tennis" > Table Tennis < br >
  14. < input type="checkbox"
    name = "t1[]" value="Volleyball"> Volleyball < BR >
  15. < input type="Submit">
  16. < /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 ...

  • Related Article

    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.