标签:user 表单 empty 数据 rom val put 函数 字符串转换
php数组转换字符串及复选框如何勾选中,应用到函数 implode explode
复选框被选中后如何保存数据,表单提交过来为数组,要转换字符串 用到函数implode
if(!empty($_POST[‘yuyan‘])){
$bbyuyan=implode(",", $_POST[‘yuyan‘]);
}
if(!empty($_POST[‘fenge‘])){
$bbfenge=implode(",", $_POST[‘fenge‘]);
}
if(!empty($_POST[‘biaoqian‘])){
$bbbiaoqian=implode(",", $_POST[‘biaoqian‘]);
}
复选框显示如何被勾选,这时候要把字符串转换数组 用到函数 explode
if(!empty($users[‘yuyan‘])){
$users[‘yuyan‘]=explode(",",$users[‘yuyan‘]);
}
if(!empty($users[‘fenge‘])){
$users[‘fenge‘]=explode(",",$users[‘fenge‘]);
}
if(!empty($users[‘biaoqian‘])){
$users[‘biaoqian‘]=explode(",",$users[‘biaoqian‘]);
}
复选框如何被显示,下面实例
<input name="biaoqian[]" value="晚上可录" type="checkbox" {#foreach item=biaoqian1 from=$users.biaoqian#}{#if $biaoqian1 eq "晚上可录"#} checked="checked" {#/if#}{#/foreach#}/>晚上可录
<input name="biaoqian[]" value="周六可录" type="checkbox" {#foreach item=biaoqian1 from=$users.biaoqian#}{#if $biaoqian1 eq "周六可录"#} checked="checked" {#/if#}{#/foreach#}/>周六可录
<input name="biaoqian[]" value="周日可录" type="checkbox" {#foreach item=biaoqian1 from=$users.biaoqian#}{#if $biaoqian1 eq "周日可录"#} checked="checked" {#/if#}{#/foreach#}/>周日可录
<input name="biaoqian[]" value="起录价低" type="checkbox" {#foreach item=biaoqian1 from=$users.biaoqian#}{#if $biaoqian1 eq "起录价低"#} checked="checked" {#/if#}{#/foreach#}/>起录价低
复选框要比单选框要复杂些,单选框跟普通表单一样,这里不说了
文章转载(玖乐网络 96net.com.cn)
标签:user 表单 empty 数据 rom val put 函数 字符串转换
原文地址:https://www.cnblogs.com/96net/p/9451438.html