Reputation: 71
I've got an array being returned in this format:
a:1:{i:0;i:305;}
I can't seem to unserialize()
it to access the 305
. Anyone have an idea on what I can do?
Query in WordPress:
$order_id = $wpdb->get_row("SELECT meta_value FROM wp_postmeta WHERE post_id=" . $t->object_id . " AND meta_key='wpc_inv_order_id");
I attempted to use:
$str = $order_id->meta_value;
$a = unserialize($str);
var_dump($a);
echo $a;
which resulted in bool(false)
.
However, it appears that by just doing echo $order_id->meta_value;
it somehow unserialized itself and is now giving me the ID value in the serialized array.
So by doing:
$str = $order_id->meta_value;
echo $str;
I'm getting output 305
on the above.
Thank you for your help!
Upvotes: 1
Views: 1107
Reputation: 26153
Looking what is result of unserialize
$str = 'a:1:{i:0;i:305;}';
var_dump($a = unserialize($str));
array(1) {
[0]=>
int(305)
}
So take it by$a[0];
Upvotes: 2