douyan8772 2018-06-11 10:16
浏览 192

将数组从php存储到html输入元素中

I need to store an array from php into a HTML input hidden field.

PHP Controller :

    $docNames = array();
    if(!empty($records))
    {
        foreach($records as $item)
        {
            array_push($docNames, $item['description']);
        }
    }
    $this->f3->set('docNames', $docNames);

HTML:

<form>
  <input type="hidden" name="docNames[]" value="<?php echo $docNames; ?>">
</form>

But I am not being able to do so. How can I store the array?

  • 写回答

2条回答 默认 最新

  • dongxu1875 2018-06-11 10:21
    关注

    Have a look at serialize:

    http://php.net/manual/en/function.serialize.php

    And use unserialize() to unpack.

    Also, make sure the content (value in your html) is encoded. Eg, you don't want " in your content, because that terminates the string for value.

    You can use htmlentities for that:

    http://php.net/manual/en/function.htmlentities.php

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大