我尝试在google和SO上找到解决方案,但是我没有解决方案。
我有类似的代码。
$index = 0;
while (some condition here) {
if ($index < 4) {?>
<div class="first4">
<p>Some text here</p>
</div>
<?php }
else{
$check=0;
if ($check==0){?>
<div class="displayOnceInwhile">
<?php $check=1; }?>
<div class="Insideaboveclass"></div>
<?php }
$index++;}?>
我在上面的代码中所做的是,如果$index
小于4,则内部文本将显示否则$check
将仅在循环中运行一次,但无法正常工作。另外,请注意,在这里我感到困惑,我应该在哪里关闭displayOnceInwhile
和关闭</div>
。
预期结果
<!--first 4 will display-->
<div class="first4"><p>Some text here</p></div>
<div class="first4"><p>Some text here</p></div>
<div class="first4"><p>Some text here</p></div>
<div class="first4"><p>Some text here</p></div>
<!--Set will display like this-->
<div class="displayOnceInwhile">
<div class="Insideaboveclass"></div>
</div>