Home  >  Article  >  Backend Development  >  How to get the value of checkbox in PHP

How to get the value of checkbox in PHP

尚
Original
2019-10-28 14:51:503207browse

How to get the value of checkbox in PHP

php method to get the value of the check box:

HTML code:

<form id="form1" name="form1" method="post" action="checkbox.php">
<input type=checkbox name=checkbox[] value="1">
<input type=checkbox name=checkbox[] value="2">
<input type=checkbox name=checkbox[] value="3">
<input type=checkbox name=checkbox[] value="4">
<input type=checkbox name=checkbox[] value="5">
<input type="submit" name="button" id="checkbox" value="提交" />
</form>

PHP code:

<?php
$text1=$_POST[&#39;checkbox&#39;];
for($i=0;$i<count($text1);$i++)
{
$yourwant = $text1[$i]; 
echo $yourwant."<br/>";
}
?>

The predefined $_POST variable is used to collect values ​​from the form with method="post".

Information sent from a form with the POST method is invisible to anyone (will not be displayed in the browser's address bar), and there is no limit on the amount of information sent.

Recommended: php server

The above is the detailed content of How to get the value of checkbox in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn