PHP for loops

Any loop allows you to run some code over and over again. FOR loops run for a set number of times.

Open the arraysandloops.php page you just created in your editor.

After the existing PHP code (just after the PRE, PRINT_R, PRE lines) add this loop:

echo "<p>The four names were";
for ($i=0; $i<=3;$i=$i+1) {
    echo " $names[$i]";
}
echo ".</p>";                        
        

There is a lot of new stuff in that loop:

Save the file and upload it. It should echo all four names to the Web page. Look at the source. Fiddle with the code until you understand how a FOR loop works.

submit to reddit Delicious Tweet