简体   繁体   中英

Array to String conversion error in Codeigniter. result_array() and array_unique()

I just what to turn the result array from my query (which is only has one column) to a unique array so it doesnt have repeated elements.

I don't know what else to do, I've tried everything, what am I doing wrong?

Model:

public function get_info()
    {
        $this->db->select('column');
        $this->db->from('table');
        $query=$this->db->get()->result_array();

        $out=array_unique($query);
        return $out;

    }

Controller:

public function index()
{
    $this->load->model('the_model');
    $data['stuff']=$this->the_model->get_info();
    $this->load->view('the_view',$data);
}

View:

       <?php 
          foreach($stuff as $i)
         {
          echo "$i['column']}";
         }
        ?>

The error I get is this:

A PHP Error was encountered 
Severity: Notice 
Message: Array to string conversion 
Filename: models/the_model.php

Add a DISTINCT in the query so the result doesn't have repeated values.

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;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM