gpt4 book ai didi

php - 简单数组 foreach

转载 作者:行者123 更新时间:2023-12-02 06:56:08 24 4
gpt4 key购买 nike

我敢肯定这很简单......但我似乎无法弄明白。我需要向每个提及要点的电子邮件地址发送一封电子邮件。但是两封邮件都有36分。

$emails = $userTools->weeklyMail();

打印_r:

Array
(
[0] => Array
(
[0] => email1@gmail.com
[1] =>
[2] => 36
)

[1] => Array
(
[0] => email2@gmail.com
[1] =>
[2] => 25
)

)

循环:

foreach($emails as $email)
{
$email = $email[0];
$subject = "You have ".$email[2]." points!!! !!!";
// The message
$message = "Hello\r\nYou have ".$email[2]." points .";
$helperClass->sendEmail($email, $subject, $message);
}

最佳答案

您的问题是您覆盖了引用变量 $email,这意味着 $email[2] 未定义。

更改为:

foreach($emails as $email)
{
// $email = $email[0]; You can't use $email[2] if $email is overwritten
$subject = "You have ".$email[2]." points!!! !!!";
// The message
$message = "Hello\r\nYou have ".$email[2]." points .";
$helperClass->sendEmail($email[0], $subject, $message);
}

关于php - 简单数组 foreach,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31049957/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com