初學者很少用到復選框,用到復選框的時候對取值有些迷惑,下面給出取值方法:
<?php
if (empty($_POST['language'])){
echo '請選擇';
}else {
print_r($_POST['language']);
foreach ($_POST['language'] as $l){
echo $l."<br />";
}
}
?>
<form method="post" action="">
<input type="checkbox" name ="language[]" id ="language[]" value="1">c
<input type="checkbox" name ="language[]" id ="language[]" value="2">c++
<input type="checkbox" name ="language[]" id ="language[]" value="3">java
<input type="checkbox" name ="language[]" id ="language[]" value="4">php
<input type="checkbox" name ="language[]" id ="language[]" value="5">python
<input type="submit">
</form>