先用php获得checkbox多选择框的内容,是一个数组Array,再把数组Array拼接在一起就行了。
工具/原料
phpstudy
PC
php获取checkbox复选框的内容
1、罕铞泱殳checkbox复选框示例:<input type="checkbox" 荏鱿胫协name="like[]" value="骑车">骑车<input type="checkbox" name="like[]" value="爬山">爬山<input type="checkbox" name="like[]" value="游泳">游泳文件index.html全部代码<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Title</title></head><body><form action="test.php" method="post" name="frm"><input type="checkbox" name="like[]" value="骑车">骑车<input type="checkbox" name="like[]" value="爬山">爬山<input type="checkbox" name="like[]" value="游泳">游泳</form></body></html>
2、用一个数组来存接收CheckBox数据$like = $_POST['like'];
3、用implode函数把数组连接起来echo '你的选择:'.implode(',',$l足毂忍珩ike);文件test.php全部代码<?phpif($_POST['like'] ){$like = $_POST['like'];echo '你的选择:'.implode(',',$like);}?>
4、附:函数string implode(string glue, array pieces);功能:将数组的内容组合成一个字符串。参数: glue 可选。规定数组元素之间放置的内容。默认是 ""(空字符串)。 pieces 必需。要组合为字符串的数组。返回值:返回由数组元素组合成的字符串。