Reputation: 129
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.
Upvotes: 1
Views: 135
Reputation: 6601
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.
Upvotes: 3