Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/260.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 在发送电子邮件和短信时,Foreach循环迭代出现问题_Php_Mysql_Curl_Foreach - Fatal编程技术网

Php 在发送电子邮件和短信时,Foreach循环迭代出现问题

Php 在发送电子邮件和短信时,Foreach循环迭代出现问题,php,mysql,curl,foreach,Php,Mysql,Curl,Foreach,我在WGET-linux命令(比如CRON)的支持下定期运行PHP函数。在本例中,对于每次执行,我将从数据库中获取1500条记录,并迭代foreach循环。在foreach中,我需要运行一个限制为20次迭代的for循环。在for循环中,我将使用switch case检查当前操作 $samplearray = array('.....'); // Multidimensional array contains 1500 rows foreach($samplearray as $samplearr

我在WGET-linux命令(比如CRON)的支持下定期运行PHP函数。在本例中,对于每次执行,我将从数据库中获取1500条记录,并迭代foreach循环。在foreach中,我需要运行一个限制为20次迭代的for循环。在for循环中,我将使用switch case检查当前操作

$samplearray = array('.....'); // Multidimensional array contains 1500 rows
foreach($samplearray as $samplearr)
{
     for($s=1;$s<=20;$s++)
     {
          $step = mysql_query("SELECT steptype FROM steptable WHERE camapign=$samplearr['campaign'] AND currentstep=$s")or die(mysql_error());
          $stepdet = mysql_fetch_array($step);
          switch($stepdet ['steptype'])
          {
               case 'email':
                   // PHP mailer script to send emails
               break;
               case 'sms':
                   // Third party URL to send SMS using Curl execution
               break;
               case 'others':
                   // DB updations - Mysql Query
               break;
               // DB updations - Mysql Query
          }
     }
}
$samplearray=array(“……”);//多维数组包含1500行
foreach($samplearray作为$samplearr)
{

对于($s=1;$s由于for循环,在
$samplearray
中匹配
email
sms
的每个条目都将被发送20次。为什么您不理解您编写的代码?您有1500次迭代的外部循环和20次循环的内部循环,因此您的switch语句将被运行30000次。并且为了帮助您理解如何执行我们的代码正在工作,将数组减少到10个元素,计数器减少到2个,并添加显示当前数组元素和计数器值的调试打印语句。祝你好运。我不太明白你怎么能
而不是
看到这是如何发送重复项的。看起来你有意编写了代码,以便每个数组值发送20次.Thaillie,抱歉,我遗漏了代码中的几行。我现在添加了它。重复计数没有找到问题的模式。对于eq,。在1500次迭代的场景中,一次发送700封电子邮件,两次发送300封电子邮件,三次发送500封电子邮件。这些计数在连续迭代中有所不同。如果我将电子邮件和短信部分隐藏在案例中,则其w工作正常(已签入DB)。