This week I am covering loops in this article Right, so lets start. There are 3 different types of loops:
And here are their usages: "; } ?> This will print "Loop count : 0", "Loop count : 1" ... "Loop count : 19". Pay attention that it will end at 19, as I did not tell it to be "$i <= 20". Pay carefull attention to this, as many developers make this common mistake. Next up, the foreach loop: "is", "so" => "awesome" ); // This is the first foreach example foreach( $my_array as $array_element ) { echo $array_element . " "; } echo "
"; // This is the second foreach example // In this one I use both the key and value of each array element, not just the value foreach( $my_array2 as $key => $value ) { echo $key . " " . $value . " "; } ?> This will print out two lines of "This is so awesome" underneath each other. View the sytaxes, and note that you can any names for the variables that store the key and value pairs, just easier to call it $key and $value, makes it simpler to identify them :) Next up, the while loop: [...]
Later! John Clarke :)
This entry was posted
on Friday, March 5, 2010
at 10:36 AM
. You can follow any responses to this entry through the
comments feed
.