1

Controller:

$student = $this->school_model->get_school_students($institute);    
echo "<pre>";    
print_r($student);    
echo implode(',',$student);    
exit;    

Model:

function get_school_students($institute=''){    
    $query=$this->db->query("SELECT id FROM users as u where     
    u.current_educational_institution = '$institute' and u.deleted=0 AND     u.role=2");    
    $result=$query->result_array();    
    if($query->num_rows()>0){     
        // $output=array();    
        $output=$result;    
    }    
    return $output;    
}

Output:

Array    
(    
    [0] => Array    
        (    
            [id] => 280    
        )    

    [1] => Array    
        (    
            [id] => 282    
        )    
)    

Array,Array ......   

I want to echo 280,282 from implode but it is showing array array??? help me?

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98

1 Answers1

3

Reason:- Data that you are getting from function is multi-dimensional-array and implode() works on single-dimensional-array .That's why you are facing problem.

Solution:-

convert your multi-dimensional-array to single-dimensional-array using array_colum()like below:-

echo implode(',',array_column($student,'id'));

Output:-https://eval.in/829544

Reference:- array_column()

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98