当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Can't figure out how to create an array within Foreach loop to spit out email list using Codeigniter framework

问题描述:

MODEL:

public function get_app(){

$this->db->select('email');

$this->db->from('app');

$query = $this->db->get();

return $query->result();

}

CONTROLLER:

 $this->load->model('po_model');

$this->po_model->po_insert($data);

$emails = $this->po_model->get_app();

foreach($emails as $email){

$app = array('app_email'=> $email->email);

}

//SEND NOTIFICATION

$to = $app['app_email'];

I need to create a list of emails retrieved from the db, to add to the mail function to send out notifications, but I'm having a hard time containing that list in an array using a foreach loop to gather email.

网友答案:

here is little modification for your code

$this->load->model('po_model');
$this->po_model->po_insert($data);
$emails = $this->po_model->get_app();

$app= array();
foreach($emails as $email){
  $app[] =  $email->email;
}
//SEND NOTIFICATION
$to = implode(',',$app);

above code add all email in array, when you want to send implode them with code and send to all. if you want to send everybody a single email just put your mail code in loop and send mail.

分享给朋友:
您可能感兴趣的文章:
随机阅读: