我正在尝试打印此单词按查询,但该变量在该数组中不起作用(这些数字只是示例)。它只取第一个数字53而不是其他数字。
$catfeaturenumbers = '53,57,4294,71';
$categoryfeatured = array($catfeaturenumbers);
$featured = array(
'post__in' => $categoryfeatured
);
答案 0 :(得分:1)
我想你想要的东西如下: -
<?php
$catfeaturenumbers = '53,57,4294,71';
// create an array through explode
$categoryfeatured = explode(',',$catfeaturenumbers);
echo "<pre/>";print_r($categoryfeatured); // print array to check
$featured = array(
'post__in' => $categoryfeatured
);
注意: - 如果您想将原始字符串用于IN QUERY
(示例SELECT * FROM <table> WHERE id IN (your original string data)
),请执行以下操作: -
$categoryfeatured = "'".implode("','",explode(',',$catfeaturenumbers))."'";
echo $categoryfeatured;
两个代码输出链接: - https://eval.in/662140