2017-05-29 130 views
0

如果條件爲false,如何開始foreach與新項目。 我有這樣的代碼:開始從開始的foreach

foreach($a_auctions as $auction){ 
     # get the winner 
     if($auction['for_canada'] == 1 && $isFromCanada){ 
      // another solution to start the foreach with new item (break, exit) ? 
      $this->a_returnData[] = array(
       'winner'  => 'pseudo', 
       'title'  => 'title', 
       'price'  => 200, 
      ); 
     }else{ 
      $this->a_returnData[] = array(
       'winner'  => 'pseudo', 
       'title'  => 'title', 
       'price'  => 200, 
     ); 
     } 
    } 

我想在如果開始用foreach的新項目,如果條件不成立,這個想法是爲了避免重複的代碼。我添加了一條評論。

+0

請你與你的期望的輸出更新您的問題 –

+0

請更新您的代碼,它是越野車! –

+0

@BunkerBoy我不想在第一個中複製代碼...如果可以添加中斷或繼續? – user7424312

回答