分享下php处理复选框checkbox默认值的方法,代码如下:
<html> <head> <title>使用复选框的默认值-www.jb200.com</title> </head> <body> <?php $food = $_GET[food]; $self = htmlentities($_SERVER['PHP_SELF']); if (!empty($food)) { echo "您选择的内容为:<br />"; foreach($food as $foodstuf) { echo "<strong>".htmlentities($foodstuf)."</strong><br />"; } } else { echo ("<form action="$self" "); echo ('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!" >'); } ?> </body> </html>