php 实例:处理同名 checkbox 复选框
本文介绍下,
php 实例之处理同名称的 checkbox 复选框的内容,有需要的朋友,参考下吧。
在
php 中,接收同名的复选框的值,需要用到数组,这里分享一段代码,希望对大家有所
帮助。
<html>
<head>
<title>使用默认复选框值</title>
</head>
<body>
<?php
$food = $_GET["food"];
if (!empty($food)){
echo "选择的食物有: <strong>";
foreach($food as $foodstuff){
echo '<br />'.htmlentities($foodstuff);
}
echo "</strong>.";
}
else {
echo ('
<form action="'. htmlentities($_SERVER["PHP_SELF"]).'" method="GET">
<fieldset>
<label>
Italian
<input type="checkbox" name="food[]" value="Italian" />
</label>
<label>
Mexican
<input type="checkbox" name="food[]" value="Mexican" />
</label>
<label>
Chinese
<input type="checkbox" name="food[]" value="Chinese" checked="checked" />
</label>
</fieldset>
<input type="submit" value="Go!" />
</form> ');
}
?>
</body>
</html>
2,检查复选框是否包含某些值的例子
<?php