[英]for loop inside if condition in php
I need to run set of code inside for-loop
only if certain condition is satisfied like:仅当满足某些条件时,我才需要在
for-loop
运行一组代码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
I want the我想要to run regardless of the if- for condition.
无论 if- for 条件如何运行。 How can I loop like this?
我怎么能像这样循环? Any help would be greatly appreciated.
任何帮助将不胜感激。
Your question as stated is self–answering — if you need to have if
inside of a loop you just... can.如上所述,您的问题是自我回答的——如果您需要在循环中使用
if
,您只需……可以。 :) :)
Looking at your code (which is not quite PHP looking?..) you also seem to want to terminate the loop conditionally?看看你的代码(这不是很像 PHP 吗?..)你似乎也想有条件地终止循环?
In PHP loops can be controlled with break
and continue
.在 PHP 中,可以使用
break
和continue
控制循环。 You example looks like it's trying to break
the loop conditionally.你的例子看起来像是试图有条件地
break
循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.