I will try it again. I will also moving forward put tags to put my code in the box.
That's good. Remember, to learn, you need to practice, so do not be afraid to try before reading a "model answer".
In an attempt to provide a better "model answer", this would be my solution:
<?php
$numbers = array();
// fill array with numbers from 1 to 100
for ($i = 1; $i <= 100; ++$i)
{
$numbers[] = $i;
}
// print array using a while statement
while (list($key, $value) = each($numbers))
{
echo $value . ' ';
}
?>
Notice how I populated the array - it is a numerically indexed array since I let PHP calculate the index at which to append new elements with "$numbers[] = $i" instead of "$numbers[$i] = $i". Note also the for loop.
For printing, I chose to use [man]list/man and [man]each/man. Basically, each() returns the current key/element pair from the array and advances the internal array pointer/cursor, and list() assigns the key to $key and the element to $value. If you did not have the restriction of using a while loop, you would use:
// print array
foreach ($numbers as $key => $value)
{
echo $value . ' ';
}
or better yet, since you do not need the key:
// print array
foreach ($numbers as $value)
{
echo $value . ' ';
}
EDIT:
Incidentally, if you had no restrictions at all, you could just use [man]range/man and [man]implode/man, e.g.,
<?php
// fill array with numbers from 1 to 100
$numbers = range(1, 100);
// print array
echo implode(' ', $numbers);
?>
Of course, this would not teach you about loops, but about range() and implode().