I have the array array ( [0] => array(1,2,3,4,5) [1] => array(6,7,8,9,10))
and I would like to display it like this:
-
Here is another way to do this (demo here):
elements per -
$aElements = 2;
$totalElems = count($tab);
//open the list
echo "
- ";
for($i=0;$i<$totalElems;$i++){
if($i != 0 && ($i%$aElements) == 0){ //check if I'm in the nTh element.
echo "
- "; //if so, close curr
- and open another
- element
}
//print elem inside the
-
echo "".$tab[$i]."";
}
//close the list
echo "
";
?>
Tip explanation: $i%n (mod) equals 0 when $i is the nTh element (remainder of division is 0)
EDITED: made a general solution