Return to Snippet

Revision: 66337
at April 20, 2014 01:51 by fedek6


Initial Code
/* how many items to loop: */
$count = 6;
/* how many items in row: */
$n = 3;
for( $i=1; $i<=$count; $i++ ) {
	// add header
	if(  $i%$n === 1 || $i === 1 ) {
		echo 'header<br>';
	}
	
	// echo content
	echo "content no. $i<br>";
	
	// add footer
	if( $i%$n === 0 || $i === $count ) {
		echo 'footer<br>';
	}
}

Initial URL

                                

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

Initial Title
Add header and footer every n times (php loop)

Initial Tags
header

Initial Language
PHP