Php Codeigniter中的数组到字符串转换错误。结果_数组()和数组_唯一()
我只是想知道如何将结果数组从我的查询(只有一列)转换成一个唯一的数组,这样它就不会有重复的元素 我不知道还能做什么,我什么都试过了,我做错了什么 型号:Php Codeigniter中的数组到字符串转换错误。结果_数组()和数组_唯一(),php,arrays,codeigniter,Php,Arrays,Codeigniter,我只是想知道如何将结果数组从我的查询(只有一列)转换成一个唯一的数组,这样它就不会有重复的元素 我不知道还能做什么,我什么都试过了,我做错了什么 型号: public function get_info() { $this->db->select('column'); $this->db->from('table'); $query=$this->db->get()->result_array();
public function get_info()
{
$this->db->select('column');
$this->db->from('table');
$query=$this->db->get()->result_array();
$out=array_unique($query);
return $out;
}
控制器:
public function index()
{
$this->load->model('the_model');
$data['stuff']=$this->the_model->get_info();
$this->load->view('the_view',$data);
}
视图:
在查询中添加一个DISTINCT,这样结果就不会有重复的值
public function get_info()
{
$this->db->select('column');
$this->db->distinct();
$this->db->from('table');
$query=$this->db->get()->result_array();
$out=array_unique($query);
return $out;
}
你为什么要对获取的结果集应用
array\u unique
,只需在查询中添加一个DISTINCT
,我真的很糟糕,我正在学习,谢谢你的回答!虽然我仍然想知道它为什么不起作用:/array\u unique
在获取的数组上不起作用,因为这将导致多维行数组,它必须是一个平面数组,这样做是错误的方法,只需使用活动记录中也可用的distinct
,就可以得到唯一的值,然后,您只需使用print\r($query)@Ghost ohhh!!非常感谢!
A PHP Error was encountered
Severity: Notice
Message: Array to string conversion
Filename: models/the_model.php
public function get_info()
{
$this->db->select('column');
$this->db->distinct();
$this->db->from('table');
$query=$this->db->get()->result_array();
$out=array_unique($query);
return $out;
}