0

This question already has an answer here:

I have used get_post_meta($post->ID) to get all custom fields for my post since I have many of htem. Some of them were checkbox values and var_dumping the variable gives me this

array (size=1) 0 => string 'a:3:{i:0;s:6:"ozujak";i:1;s:7:"travanj";i:2;s:7:"svibanj";}

How do I echo those values?

I have tried var_dump(json_decode($meta['my_var'])); but it gives me null

marked as duplicate by Howdy_McGee, TheDeadMedic, birgire, Pieter Goosen, fuxia Jan 17 '16 at 11:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

The values look like they have been serialized using maybe_serialize( $data ).

If that's the case, then you can reverse that with maybe_unserialize( $original ).

As per this answer, unserialize( $str ) will also create a PHP value from a stored representation.


Try:

$mydata = 'a:3:{i:0;s:6:"ozujak";i:1;s:7:"travanj";i:2;s:7:"svibanj";}';

$mydata = unserialize($mydata);

echo $mydata[0]; // ozujak
  • The maybe is used in cases where you aren't quite sure. Because you know, unserialized will eventually be called. – jgraup Jan 8 '16 at 20:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.