2 回答
TA贡献1821条经验 获得超4个赞
我建议这样的解决方案:
$idquestionCollect = ["34 1", "7 2", "29 3", "29 4", "28 5", "27 6", "27 7", "28 8", "28 9", "34 10", "34 11", "34 12", "34 13"];
$results = [];
foreach ($idquestionCollect as $separateID) {
[$one, $two] = explode(" ", $separateID);
$results[] = [
"id" => rtrim($two),
"result" => rtrim($one),
];
}
usort($results, function($el1, $el2){
return $el1['result'] > $el2['result'];
});
$listIDs = '"' . implode('","', array_column($results, 'id'));
$query = "SELECT * FROM articles where id in($listIDs)";
...
TA贡献1856条经验 获得超5个赞
创建一个scores索引数组id,然后对其进行排序,然后提取键会更容易:
foreach ($idquestionCollect as $separateID) {
$parts = explode(" ", $separateID);
if ($parts[0] < 40) {
$listIDs[$parts[1]] = $parts[0];
}
}
asort($listIDs);
$listIDs = implode(',', array_keys($listIDs));
另一种娱乐方式:
preg_match_all('/(\d+) (\d+)/', implode('-', $idquestionCollect), $matches);
$listIDs = array_combine($matches[2], $matches[1]);
asort($listIDs);
$listIDs = implode(',', array_keys($listIDs));
对于您的数据,两者都会产生:
2,3,1
- 2 回答
- 0 关注
- 169 浏览
添加回答
举报