dongpi2503 2013-05-28 15:24
浏览 60
已采纳

我可以将序列化数组保存到数据库,它有一些参考子数组吗?

The PHP code I am interating through is as follows for the Update process:

$data = $_POST;
foreach ($data['answers'] as &$d):
    if(!isset($d['default'])):
       $d['default'] = "false";
    endif;
endforeach;

And when I var_dump it after that iteration, I get the following:

array(2) {
  ["question"]=>
  string(20) "Which did you like?"
  ["answers"]=>
  array(6) {
    [0]=>
    array(2) {
      ["default"]=>
      string(4) "true"
      ["option"]=>
      string(5) "First"
    }
    [1]=>
    &array(2) {
      ["option"]=>
      string(5) "Second"
      ["default"]=>
      string(5) "false"
    }
  }
}

As you can see, the second array has "&array" keyword, I am assuming that's implying a reference. My question is, can I serialize this array and save it into MYSQL DB? I was getting some data error on the display page after, so I want to make sure if this has anything to do with this.

UPDATE Error message I get on the display page is that Undefined index: option

  • 写回答

2条回答 默认 最新

  • dongyuhui0418 2013-05-28 15:36
    关注

    From the docs:

    serialize() handles all types, except the resource-type. You can even serialize() arrays that contain references to itself. Circular references inside the array/object you are serializing will also be stored. Any other reference will be lost.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请提供一个符合要求的网页链接。
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码