您能建议我什么是不重复结果转换的好方法吗?
$numbers = array ('1', '5', '10');
foreach ($numbers as $number){
$query[] = $this->db->query("SELECT name, country FROM name WHERE id= '" . (int)$number .'"")
}
结果
Array (
Array (
name = ivan
country = en
)
Array(
name = Peter
country = en
)
Array (
name = sisi's
country = en
)
)
我该如何对结果进行排序
Array(
country = en
name = array (
sisi's
Peter
Ivan
)
)
答案 0 :(得分:0)
您需要修改查询。
$numbers = array ('1', '5', '10');
$sql = "SELECT DISTINCT country,
GROUP_CONCAT(name) AS name
FROM name
WHERE id IN(".implode(',',$numbers).")
GROUP BY country";
$this->db->query($sql);
比得到结果后,您可以使用explode函数将字符串名称转换为数组。