我需要你的建议和帮助
我从数据库中获取了一个数据数组,我想逐个处理每个元素而不使用foreach循环,比如
弹出元素a并在完成后处理它 pop元素b并在完成后处理它 pop元素b并处理它
直到数组变空,然后脚本可以退出
目前我正在使用foreach循环遍历数据,但事情并没有找到。
$loaded_message = $this->lib->load_queued_messages();
if(count($loaded_message) == 0) {
die ('Nothing to do');
}
foreach($loaded_message as $tosend)
{
if($this->lib->send_sms($tosend['from'], $tosend['msg'], explode(',', $tosend['numbers']), $tosend['owner'], $tosend['qid']))
{
// Remove the message from queue
$this->lib->remove_msg_from_queued_message($tosend['qid']);
$this->lib->log('message #' . $tosend['qid']. ' sent and removed from queue', $tosend['owner']);
}else{
$this->lib->log('SENDING_ERROR: message #' . $tosend['qid']. ' not sent and remain in the queue for#', $tosend['owner']);
}
}
在日志表中我发现输入的内容是错误的消息ID,似乎消息被发送到了错误的号码,但它没有。
答案 0 :(得分:0)
你好,你可以使用像
这样的东西while(sizeof($yourarray)) {
$result = array_pop(yourarray);
...yourprocessing_here(...);
}
希望这有助于:)