I cannot figure out why this doesn’t work. It seems so simple.
It should output this.
Intro,First,Second,Third,First,Second,Third,First,Second,Third
Intro,First,Second,Third,First,Second,Third,First,Second,Third
Intro,First,Second,Third,First,Second,Third,First,Second,Third
Intro,First,Second,Third,First,Second,Third,First,Second,Third …etc
But it does not see the the $columnnum=0; and after the first line, it just goes keeps going.
Does anyone have any ideas?
$testarray = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21);
$columnnum = 0;
foreach ($testarray as $value) {
$columnnum++;
if ($columnnum == 1) {
echo "Intro, ";
}
echo "First, ";
echo "Second, ";
echo "Third";
if ($columnnum == 3) {
$columnum = 0;
echo "<br>";
}
echo " col: ", $columnnum;
}
You typoed
$columnnum=0near the end of the loop.This should be more efficient: