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

How to get the value of checkbox in PHP

Release: 2023-02-27 21:18:02
Original
3261 people have browsed it

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>
Copy after login

PHP code:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template