开发者

Processing multi-dimensional arrays without loop

开发者 https://www.devze.com 2023-02-26 05:39 出处:网络
I need your advice and help i fetched an array开发者_如何学JAVA of data from the database and i want to process each element one by one without using foreach loop, something like

I need your advice and help

i fetched an array开发者_如何学JAVA of data from the database and i want to process each element one by one without using foreach loop, something like

pop element a and process it, when finished pop element b and process it, when finished pop element b and process it

until the array become empty then the script can exit

currently i`m looping through the data using foreach loop but things are not working find.

$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']);
                }
               }

Inside the log table i discovered that entry was made for wrong message id and it seems like message was sent to wrong number but it does not.


hi mate you can use something like

while(sizeof($yourarray)) {
  $result = array_pop(yourarray);
  ...yourprocessing_here(...);
}

hope this helps :)

0

精彩评论

暂无评论...
验证码 换一张
取 消