我使用PHP核心序列化序列化关联数组
$additional_email = serialize($customer->getData('addtionalemail'));
之后,将该值保存在Mysql数据库中
s:209:"a:1:{i:0;a:1:{i:0;a:5:{s:16:"additional_email";s:13:"test@test.com";s:9:"record_id";s:1:"0";s:26:"apply_to-prepared-for-send";a:1:{i:0;s:1:"0";}s:8:"apply_to";a:1:{i:0;s:1:"0";}s:10:"initialize";s:4:"true";}}}";
当我反序列化以上值时,它不起作用。在序列化和反序列化之前,我使用了诸如base_64_encode和解码之类的解决方案,但它不能解决问题,还使用了preg_match解决方案,但没有运气。
我使用unserialize online tool,这也将无法反序列化上面的字符串。序列化值有问题,有人可以为我指出正确的方向吗?
答案 0 :(得分:1)
您似乎已经以某种方式serialize
将值两次了。运行unserialize
两次将撤消以下操作:
print_r(unserialize(unserialize('s:209:"a:1:{i:0;a:1:{i:0;a:5:{s:16:"additional_email";s:13:"test@test.com";s:9:"record_id";s:1:"0";s:26:"apply_to-prepared-for-send";a:1:{i:0;s:1:"0";}s:8:"apply_to";a:1:{i:0;s:1:"0";}s:10:"initialize";s:4:"true";}}}";')));
输出:
Array (
[0] => Array (
[0] => Array (
[additional_email] => test@test.com
[record_id] => 0
[apply_to-prepared-for-send] => Array (
[0] => 0
)
[apply_to] => Array (
[0] => 0
)
[initialize] => true
)
)
)