你在做什么是存储"1,2,3,4"
数据库中的一个字符串值,当你试图构建一个数组从它像array("1,2,3,4")
你最终只是分配一个单一的值到新的数组。这就是为什么它只包含一个值。
您需要以可序列化的格式存储您的值,以便在将其保存到数据库后可以将其转换回数组。有很多方法可以做到这一点,我相信其他人会举些例子:
JSON encode它
json_encode(array(1,2,3,4)); // store this in your db
json_decode($cat_data['sec1array']); // outputs an array
或者,你可以使用PHP serialize
serialize(array(1,2,3,4)); // store this in your db
unserialize($cat_data['sec1array']); // outputs an array
如果你要保持你的字符串,你可以explode it:
explode(',', $cat_data['sec1array']); // outputs your array of 1,2,3,4.
Usi任何这些方法都可以工作。最后你会得到一个例子:
$seconearray = explode(',', $cat_data['sec1array']);
$args = array(
'post__in' => $seconearray
);
谢谢你,我用爆炸选项,修复它。 – Forest
@Forest试着接受答案,以便我们知道这是正确的答案。谢谢 – Firefog
接受,因为我的低代表不能upvote。 – Forest