php checkbox及select多选取值的简单例子

发布时间:2019-08-15编辑:脚本学堂
php代码中获取checkbox或select多选列的值,一个简单的示例,供初学的朋友参考。

完整代码如下:

<html>
<head><title>checkbox select取值_www.jb200.com</title>
</head>
<body >
<?php $e_ary=array('PHP','C++') ?>
<form name="form1" action="testsubmit.php" method="post">
<input name="choose[]" type="checkbox" value="PHP" <?php if(is_array($e_ary)){ echo in_array('PHP',$e_ary)?'checked':'';} ?>>PHP
<input name="choose[]" type="checkbox" value="VB" <?php if(is_array($e_ary)){ echo in_array('VB',$e_ary)?'checked':'';} ?>>VB
<input name="choose[]" type="checkbox" value="C++" <?php if(is_array($e_ary)){ echo in_array('C++',$e_ary)?'checked':'';} ?>>C++
<select name=select[] multiple>
<option  value="PHP"<?php if(is_array($e_ary)){ echo in_array('PHP',$e_ary)?'selected':'';} ?>>PHP</option>
<option  value="VB" <?php if(is_array($e_ary)){ echo in_array('VB',$e_ary)?'selected':'';} ?>>VB</option>
<option  value="C++" <?php if(is_array($e_ary)){ echo in_array('C++',$e_ary)?'selected':'';} ?>>C++</option>
</select>
<input name="submit" type="submit" value="submit">
</form>
</body>
</html>