for循环内,如果条件在PHP

时间:2019-02-21 06:39:50

标签: php for-loop if-statement

仅当满足某些条件时,我才需要在for-loop中运行一组代码:

@for($i = 0; $i <= $date_diffrence; $i++)
   @if(condition)
      $temp = $i; 
      @for($multDayCount=0; $multDayCount<count($dayDifferenceArr); $multDayCount++)
         $i = $dayDifferenceArr[$multDayCount];

   @endif

<code_section>  

   @if(condition)
      @endfor
       $i = $temp;
   @endif
 @endfor

无论if-for条件如何,我都希望 运行。我该如何循环?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

您所说的问题是自答的-如果您需要在循环中使用if,则可以...就可以了。 :)

看看您的代码(看起来不太像PHP吗?。),您似乎还想有条件地终止循环?

在PHP中,可以使用breakcontinue控制循环。您的示例似乎正在尝试有条件地break循环。

相关问题