Posted By

fedek6 on 04/20/14


Tagged

header loop footer


Versions (?)

Add header and footer every n times (php loop)


 / Published in: PHP
 

Simple loop for adding header and footer avery n times in loop. Useful for printing tables.

  1. /* how many items to loop: */
  2. $count = 6;
  3. /* how many items in row: */
  4. $n = 3;
  5. for( $i=1; $i<=$count; $i++ ) {
  6. // add header
  7. if( $i%$n === 1 || $i === 1 ) {
  8. echo 'header<br>';
  9. }
  10.  
  11. // echo content
  12. echo "content no. $i<br>";
  13.  
  14. // add footer
  15. if( $i%$n === 0 || $i === $count ) {
  16. echo 'footer<br>';
  17. }
  18. }

Report this snippet  

You need to login to post a comment.