I have a certain associative array which contains a list of emails. It's given below:
Array
(
[0] => Array
(
[email] => [email protected]
)
[1] => Array
(
[email] => [email protected]
)
[2] => Array
(
[email] => [email protected]
)
[3] => Array
(
[email] => [email protected]
)
)
It's being generated from the following controller code:
$data['list_of_emails'] = $this->Trainee_requisition->get_list_of_emails($id);
And the corresponding model code from where the get_list_of_emails($id) method is being accessed:
function get_list_of_emails($id){
$q = $this->db->query("SELECT `email` FROM `requisition_emails` WHERE `req_id` = $id")->result_array();
return $q;
}
In the Codeigniter documentations, I've found a way of passing a single dimensional array in the $this->mail->to() method of the Email class, but there is no example of an associative array.
My question is, how can I use the above mentioned associative array in the $this->email->to() method?
My main objective is to generate something like this:
$email_list = array('[email protected]', '[email protected]', '[email protected]', '[email protected]');
$this->email->to($email_list);
Edit:
Although Hassaan's answer is the easiest solution and meets my need perfectly, I'd still appreciate answers which can provide a way to retrieve only one column from a query which has more than one column.
For example, if my query is modified like this:
$q = $this->db->query("SELECT rem.`email`, sr.`is_approve` AS approval_status FROM `requisition_emails` rem INNER JOIN `staff_requisitions` sr ON sr.`id` = rem.`req_id` WHERE rem.`req_id` = $id")->result_array();
but I want only email column to be used from the list, then what is the best possible way?
Edit - 2:
Forgot to mention. PHP version is 5.3.