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.
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.
array(2) { [0]=> string(5) "Male" [1]=> string(6) "Female" } how do I let it show only Male and Female?$array[0] for male and $array[1] for female.$user_gender = unserialize($custom_fields['user_gender'][0]); And then I did this $user_gender = array_map('strtolower', $user_gender); But I get this error 'Warning: array_map(): Argument #2 should be an array'$user_gender is not an array, it is a string. If you just want to lowercase the string just use strtolower($user_gender) instead. The array_map would apply that function to every string in array, but using it on a string is not going to work.