简体   繁体   中英

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:

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM