Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php数组和mysql语法错误_Php_Mysql_Arrays - Fatal编程技术网

php数组和mysql语法错误

php数组和mysql语法错误,php,mysql,arrays,Php,Mysql,Arrays,我正在尝试使用SwiftMailer将电子邮件地址提取到数组()我有一个原始示例,我知道我想在其中添加什么,但从树上看不到森林。。。任何一个眼睛正常的人请: // Send the message $result = $mailer->send($message); // Send the message $failedRecipients = array(); $numSent = 0; 这就是我挣扎的地方: foreach($groups as $value) {

我正在尝试使用SwiftMailer将电子邮件地址提取到
数组()
我有一个原始示例,我知道我想在其中添加什么,但从树上看不到森林。。。任何一个眼睛正常的人请:

// Send the message
$result = $mailer->send($message);

// Send the message
$failedRecipients = array();
$numSent = 0;
这就是我挣扎的地方:

 foreach($groups as $value)
    { 
             echo "<h3>".$value."</h3>"; //this is working

    // get the email groups
    $sql="SELECT * FROM emails WHERE sendesstat=1 AND deleted=0 AND classhoz=\"".$value."\"";
    $query=mysql_query($sql);

    // fetch the emails from the group
    while($data=mysql_fetch_array($query))
                {
                  $emil="'".$data["email"]."' => '".$data["firstname"]." ".$data["surname"]."'";
                  echo $emil;
问题是
给定名称=>'A name'
我生病了,找不到语法

                  $to[ ]= $emil;            
                }
    }

foreach ($to as $address => $name)
{
  if (is_int($address)) {
   $message->setTo($name);
  } else {
   $message->setTo(array($address => $name));
}

 $numSent += $mailer->send($message, $failedRecipients);
}

printf("Sent %d messages\n", $numSent);

拜托,其他一切都正常了,只是少了这一点。谢谢

您以错误的方式定义了
$to
数组

使用此选项可在阵列上添加项

$to[$data["email"]] = $data["firstname"]." ".$data["surname"];
//  ^ Index           ^ Value
稍后,当您使用
foreach
循环时,它将很好地区分为$address和$name,就像您现在所做的那样

foreach ($to as $address => $name) {
    echo $address;
    echo $name; 
}

非常感谢,我要把我的代码:))再次非常感谢
foreach ($to as $address => $name) {
    echo $address;
    echo $name; 
}