PHP For Loop do action every 5 results

cdl_capture_2011-05-16-19_ 000

 

<?php

$total=10;
$divider=5; 

for($i = 0; $i < $total; $i++)
{
    if($i % $divider == 0)
    {
  echo 'start<br>';      //do your stuff here
    }

    echo "----loop,$i<br>";

    if($i % $divider == $divider-1 || $i==$total-1)
    {

  echo 'end<br>';      //do your stuff here
    }

}
?>

results


start

—-loop,0

—-loop,1

—-loop,2

—-loop,3

—-loop,4

end

start

—-loop,5

—-loop,6

—-loop,7

—-loop,8

—-loop,9

end

Leave a comment