Following is a value I am seeing in one of my fields in mysql for wordpress database
a:2:{i:0;i:31;i:1;i:23;}
What is this format? How can I get the valued of alternate I using PHP ?
Following is a value I am seeing in one of my fields in mysql for wordpress database
a:2:{i:0;i:31;i:1;i:23;}
What is this format? How can I get the valued of alternate I using PHP ?
You must be logged in to post a comment.
That is a
serialize()
‘d variable, you can useunserialize()
to convert back to the appropriate datatype – in this case an Array with Integer indexes and values.For WordPress there is a function called
maybe_unserialize()
which is useful for database values if you aren’t sure if it has been serialized or not.its in
serialize
form you can useunserialize()
php functionThat’s serialized data, the ‘a’ means array and the 2 represents two child parts of that array.
What I would recommend though rather than pulling information out via custom queries is to use WordPress’ inbuilt functions (get_posts, get_user_meta etc) which will safely retrieve the data and you can do so much more with it. Plus it’s built for extension meaning you’re not reinventing the wheel each time