Hi, I have an array of about two hundred items. I need to split them (echo them) in groups of about twenty, then echo html for a new table row, and then echo the next twenty, etc... In order to learn how to do this, I am starting small by using a simple example.
The following code splits the array with twenty items into bite-sized morsels of five. Is there a better or easier way to do this?? (Note: the actual coded array in production won't just be integers, but will be strings.)
<?php
// define array of numbers
$nums = array("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20");
// counter variable
$i = 0;
while ($i <= 4){
echo $nums[$i] . ", ";
$i = $i + 1;
}
echo "<br>";
while ($i > 4 && $i <= 9){
echo $nums[$i] . ", ";
$i = $i + 1;
}
echo "<br>";
while ($i > 9 && $i <= 14){
echo $nums[$i] . ", ";
$i = $i + 1;
}
echo "<br>";
while ($i > 14 && $i <= 19){
echo $nums[$i] . ", ";
$i = $i + 1;
}
?>
THanks in advance for your help!!