通常来说,php中总是只获取最后一个复选框的值,那么如何才能获取所有复选框的值?
解决办法如下:
form表单的部分代码如下:
1
2
3
4
5
|
< input type = "checkbox" name = "frm_tag[]" value = "1" >1 < input type = "checkbox" name = "frm_tag[]" value = "2" >2 < input type = "checkbox" name = "frm_tag[]" value = "3" >3 < input type = "checkbox" name = "frm_tag[]" value = "4" >4 < input type = "checkbox" name = "frm_tag[]" value = "5" >5 |
php处理POST传递过来数据的代码如下:
1
2
3
4
5
6
7
8
9
10
11
|
$str_tag = "" ; $frm_tag = $_POST [ 'frm_tag' ]; for ( $i =0; $i < count ( $frm_tag ); $i ++){ echo $frm_tag [ $i ]. "<br>" ; if ( $i ==0) $str_tag = $frm_tag [ $i ]; else $str_tag = $str_tag . "," . $frm_tag [ $i ]; } echo $str_tag ; } |
相信本文所述对大家深入掌握PHP程序设计有一定的借鉴价值。