【发布时间】:2016-02-01 18:15:30
【问题描述】:
我需要在我的循环中使用$counter 来返回这样的系列:
1 2 2 1 1 2 2 1
遗憾的是,我的数学不太好,无论我尝试什么都遇到了死胡同。 这是我尝试的最后一件事。
$counter = 0;
while( statement ) {
++$counter;
// Making sure the second element is loaded
if( $counter > 2 )
$twoloaded = true;
if( $counter >= 2 )
--$counter;
echo '<article class="post post-style-' . $counter . '"> ....... </article>';
}
最后我需要输出这样的 HTML:
<article class="post post-style-1">
...
</article>
<article class="post post-style-2">
...
</article>
<article class="post post-style-2">
...
</article>
<article class="post post-style-1">
...
</article>
<article class="post post-style-1">
...
</article>
<article class="post post-style-2">
...
</article>
【问题讨论】: