``````\$count1 = array();
\$count1[0] = "           1";
\$count1[1] = "         2 1";
\$count1[2] = "       3 2 1";
\$count1[3] = "     4 3 2 1";
\$count1[4] = "   5 4 3 2 1";
\$count1[5] = " 6 5 4 3 2 1";
for (\$b = 1;\$b <= 6;\$b++)
{
echo \$count[\$b];
echo "<br>";
}
why does this not work? it just goes on forever. How do i use the \$b to up the count of \$count[]?``````

Well.. lets begin..

First, arrays in most languages (and it looks like you're using PHP, and PHP is one of them) start at 0. So first, \$b = 0;

Second, <= 6 is not what you think it's doing. Since we start at 0 (i.e., \$count[0]), when you get up to 6 you are doing \$count[6], which is out of bounds of your array. So, \$b < 6;

After that.. I dunno. Looks fine to me. Im not sure what you mean it 'goes on forever' but I assume you get something you don't expect, and I will also assume that it has a lot to do with the errors in your code.

TL;DR;
`for (\$b = 0; \$b < 6;\$b++) { ... }`

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.