2011-04-16 99 views
0

多維數組我需要你們的建議和幫助處理,不循環

我拿來從數據庫中數據的數組,我想通過一個不使用foreach循環,像

處理每個元素的一個彈出元件並對其進行處理,完成 彈出元素b和處理它,成品 彈出元素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

後你有什麼不工作,從而使他人能夠告訴你如何解決它。 – Mat 2011-04-16 10:00:37

+4

請原諒這個問題,你爲什麼要避免循環? – 2011-04-16 10:06:03

+0

發佈更新了示例代碼。感謝@Damien和@Mat的快速回復 – elf1984 2011-04-16 10:17:46

回答

0

喜的伴侶,你可以使用類似

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

希望這有助於:)

+0

讓我試試這個 – elf1984 2011-04-16 10:48:02