Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将传入的复选框值转换为一个隐藏字段值?_Php - Fatal编程技术网

Php 如何将传入的复选框值转换为一个隐藏字段值?

Php 如何将传入的复选框值转换为一个隐藏字段值?,php,Php,我的提交页面包含一些复选框: <input type="checkbox" name="p_queue_type[]" id="p_queue_type_all" value="All"> <input type="checkbox" name="p_queue_type[]" id="p_queue_type_CR" value="CR" checked> <input type="checkbox" name="p_queue_type[]" id="p_que

我的提交页面包含一些复选框:

<input type="checkbox" name="p_queue_type[]" id="p_queue_type_all" value="All">
<input type="checkbox" name="p_queue_type[]" id="p_queue_type_CR" value="CR" checked>
<input type="checkbox" name="p_queue_type[]" id="p_queue_type_FPU" value="FPU">
<input type="checkbox" name="p_queue_type[]" id="p_queue_type_HOLD" value="HOLD" checked>
但这会导致一个无用的隐藏字段值:

<input type="hidden" name="p_queue_type[]" value="Array" />

这应该可以:

foreach ($attributes as $field => $value){
    $value = is_array($value) ? '[' . implode(',', $value) . ']' : $value;
    echo('<input type="hidden" name="'.$field.'" id="'.$field.'" value="'.$value.'" />');
};
foreach($attributes as$field=>$value){
$value=is_数组($value)“[”。内爆(“,”,$value)。“]':$value;
回声(“”);
};

它将php数组转换为html友好的数组字符串

试试这个
,它完全符合我的要求。谢谢你,乔纳森。
<input type="hidden" name="p_queue_type[]" value="Array" />
foreach ($attributes as $field => $value){
    $value = is_array($value) ? '[' . implode(',', $value) . ']' : $value;
    echo('<input type="hidden" name="'.$field.'" id="'.$field.'" value="'.$value.'" />');
};