You can set the names for the flags as an array:
<input type = "checkbox" value = "box" name = "checkbox[1]"/> <input type = "checkbox" value = "box" name = "checkbox[2]"/> <input type = "checkbox" value = "box" name = "checkbox[3]"/>
and then you will have an array in PHP ( $_POST['checkbox']
):
echo count( $_POST['checkbox'] );
otherwise, you can iterate over each of them and increase the variable:
$counter = 0; foreach( array('checkbox1', 'checkbox2', 'checkbox3') as $name ) { if( isset( $_POST[ $name ] ) { $counter++ } } echo $counter;
source share