计算多少复选框被检查php/html

use*_*815 4 html php checkbox

嗨,我是新的PHP,我想知道'checkbox'如果我点击提交后我能算多少检查.例如:

<input type = "checkbox" value = "box" name = "checkbox1"/>
<input type = "checkbox" value = "box" name = "checkbox2"/>
<input type = "checkbox" value = "box" name = "checkbox3"/>
Run Code Online (Sandbox Code Playgroud)

Gau*_*164 14

将复选框名称作为数组

<input type = "checkbox" value = "box" name = "checkbox[]"/>
Run Code Online (Sandbox Code Playgroud)

提交后试试看

$checked_arr = $_POST['checkbox'];
$count = count($checked_arr);
echo "There are ".$count." checkboxe(s) are checked";
Run Code Online (Sandbox Code Playgroud)

注:并基于该表单提交使用......无论是方法$_GET还是$_POST需要使用$_POST['checkbox']POST方法$_GET['checkbox']GET方法.

  • 这可能是正确的答案,因为不使用 `name = "checkbox[]"` 它需要检查多个值。 (2认同)