[英]How to convert JSON into an array or string?
I'm not sure if I'm allowed to ask these types of questions. 我不确定我是否可以问这些类型的问题。 Anyway, I have this array value
$custom_fields['user_gender'][0]
that outputs this: 无论如何,我有这个数组值
$custom_fields['user_gender'][0]
输出:
a:2:{i:0;s:7:"Male";i:1;s:7:"Female";}
I'm not sure how to convert this into an array or string. 我不知道如何将其转换为数组或字符串。
The example data looks like it is serialized PHP. 示例数据看起来像是序列化的 PHP。 Serializing is a way an array, string etc. can be "represented" as a textual string and can later be converted back to the original data format, using a unserialize operation.
序列化是一种方式,数组,字符串等可以“表示”为文本字符串,以后可以使用反序列化操作转换回原始数据格式。 A serialized string can be stored as text in a database and can be unserialized at any point.
序列化字符串可以作为文本存储在数据库中,并且可以在任何时候进行反序列化。
You can unserialize it with: 您可以使用以下命令对其进行反序列化 :
$array = unserialize($custom_fields['user_gender'][0]);
This should return an array. 这应该返回一个数组。 If you
var_dump
on $ array
, you can be sure it's an array. 如果你在$
array
上使用var_dump
,你可以确定它是一个数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.