我试图检索自定义视图的附加标签(WooCommerce产品附加),然后使用get_post_meta()从数据库中获取序列化数组,但unserialize()输出bool(false)。
$ProductMeta = get_post_meta($ParentProductID);
$addons = $ProductMeta['_product_addons'];
echo var_dump($addons);
上面代码的结果是
array(1) { [0]=> string(530) "a:1:{i:0;a:16:{s:4:"name";s:6:"Extras";s:12:"title_format";s:5:"label";s:18:"description_enable";i:0;s:11:"description";s:0:"";s:4:"type";s:8:"checkbox";s:7:"display";s:11:"radiobutton";s:8:"position";i:0;s:8:"required";i:0;s:12:"restrictions";i:0;s:17:"restrictions_type";s:8:"any_text";s:12:"adjust_price";i:0;s:10:"price_type";s:8:"flat_fee";s:5:"price";s:0:"";s:3:"min";d:0;s:3:"max";d:0;s:7:"options";a:1:{i:0;a:4:{s:5:"label";s:14:"Add Prosciutto";s:5:"price";s:1:"3";s:5:"image";s:0:"";s:10:"price_type";s:8:"flat_fee";}}}}" }
然后我按如下所示尝试了unserialize()函数:
$ProductMeta = get_post_meta($ParentProductID);
$addons = $ProductMeta['_product_addons'];
$addons = unserialize($addons);
echo var_dump($addons);
结果是:
bool(false)
答案 0 :(得分:1)
返回的值是一个包含一个元素的数组,但是您尝试对整个数组进行反序列化,因此您需要像unserialize($ addons [0])这样定位该元素