爆();不分离数组

时间:2015-02-11 00:34:51

标签: php

结果只是电子邮件根本没有分开。

$query  = "SELECT email FROM wp_newsman_lst_wp_users";
$result = mysql_query($query);

while($row = mysql_fetch_array($result))
{
    $new_array[$row['email']]['email'] = $row['email'];
} 

foreach($new_array as $array)
{       
   $to = $array['email'];

   $mail_list = implode(", ", (array)$to);
}

echo $mail_list;

结果只是电子邮件根本没有分开。

1 个答案:

答案 0 :(得分:2)

你必须在foreach循环之外进行implode()调用,所以请使用:

foreach($new_array as $array) {       
    $to[] = $array['email'];
     //^^ So you actually have a array
}

$mail_list = implode(", ", $to);
           //^^^^^^^ Outside of the foreach loop