Here is another way to do this (demo here ):
<?php
$tab = array(1,2,3,4,5,6,7,8,9,10);
$aElements = 2;
$totalElems = count($tab);
echo "<ul><li>";
for($i=0;$i<$totalElems;$i++){
if($i != 0 && ($i%$aElements) == 0){
echo "</li><li>";
}
echo "<a href =''>".$tab[$i]."</a>";
}
echo "</li></ul>";
?>
Tooltip explanation: $ i% n (mod) is 0 when $ i is an element of nTh (remainder of division is 0)
EDITED: made a general decision
stecb source
share