开发者

PHP foreach Check which post so far

开发者 https://www.devze.com 2023-03-14 14:09 出处:网络
Using for each I am dismantling a series of dates. foreach( $ds as $d){ echo \'<div class=\"bkback\" onclick=\"bkdates(this);\">\'.date(\'M\', strtotime(\"today + $d day\")).\'<br /><

Using for each I am dismantling a series of dates.

foreach( $ds as $d){

echo '<div class="bkback" onclick="bkdates(this);">'.date('M', strtotime("today + $d day")).'<br /><span class="bknum">'.date('d', strtotime("today + $d day")).'</span><br />
'.date('D', strtotime("today + 开发者_如何学C$d day")).'</div>';

}

What I want to do is every put a marker <div class="marker"></div> after post 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, and 85 for the purposes of a jumping Jquery scroller.

So I need away of identifying which post we are at so far.

Any ideas?

Marvellous


Increment a variable each time through the loop - something like:

$i = 0;
foreach( $ds as $d) {
    if ($i++ % 5 == 0) {
        echo '<div class="marker"></div>';
    }
}


I would just increment a counter and then check to see if it's divisible by 5.

$acounter = 0;
foreach( $ds as $d){
  $acounter++;
  if ( $acounter % 5 == 0 ) echo '<div class="marker"></div>';

  echo '<div class="bkback" onclick="bkdates(this);">'.date('M', strtotime("today + $d day")).'<br /><span class="bknum">'.date('d', strtotime("today + $d day")).'</span><br />'.date('D', strtotime("today + $d day")).'</div>';

 }


$counter = 0;

foreach( $ds as $d){

echo '<div class="bkback" onclick="bkdates(this);">'.date('M', strtotime("today + $d day")).'<br /><span class="bknum">'.date('d', strtotime("today + $d day")).'</span><br />
'.date('D', strtotime("today + $d day")).'</div>';

$counter++;

if ($counter % 5 == 0) { echo '<div class="marker"></div>'; }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消