welcomewiki has just posted in the PHP Forum forum of Wiki Newforum under the title of PHP Looping.
This thread is located at http://www.wikinewforum.com/showthread.php?t=5857
Here is the message that has just been posted:
***************
*The for Statement*
The for statement is the most advanced of the loops in PHP.
In it's simplest form, the for statement is used when you know how many times you want to execute a statement or a list of statements.
*Syntax*
for (init; cond; incr)
{
code to be executed;
} Parameters:
* *init*: Is mostly used to set a counter, but can be any code to be executed once at the beginning of the loop statement.
* *cond*: Is evaluated at beginning of each loop iteration. If the condition evaluates to TRUE, the loop continues and the code executes. If it evaluates to FALSE, the execution of the loop ends.
* *incr*: Is mostly used to increment a counter, but can be any code to be executed at the end of each loop.
*Note: *Each of the parameters can be empty or have multiple expressions separated by commas.
* *cond:* All expressions separated by a comma are evaluated but the result is taken from the last part. This parameter being empty means the loop should be run indefinitely. This is useful when using a conditional break statement inside the loop for ending the loop.
*Example*
The following example prints the text "Hello World!" five times:
<html>
<body> <?php
for ($i=1; $i<=5; $i++)
{
echo "Hello World!<br />";
}
?> </body>
</html>
*The foreach Statement*
The foreach statement is used to loop through arrays.
For every loop, the value of the current array element is assigned to $value (and the array pointer is moved by one) - so on the next loop, you'll be looking at the next element.
*Syntax*
foreach (array as value)
{
code to be executed;
} *Example*
The following example demonstrates a loop that will print the values of the given array:
<html>
<body> <?php
$arr=array("one", "two", "three"); foreach ($arr as $value)
{
echo "Value: " . $value . "<br />";
}
?> </body>
</html>
***************