For
A type of loop designed for looping through code when you know how many times you want to go though it.
Examples
PHP Code:
for($i=0;$i<8;$i++)
{
echo "I have looped though $i times<br />";
}
Foreach
Foreach is a way to loop over elements in an array.
Examples: Taken from http://us.php.net/foreach
PHP Code:
<?php
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
unset($value); // break the reference with the last element
?>
Formatting
This generally refers to the layout and readabilty of your PHP code. Good formatting includes correctly indented blocks and proper use of whitespace
Function
A function is a reuseable block of code that you can run as required. A function definition would look something like:
PHP Code:
function myFunction()
{
// function content here
}
You would then run your custom function as you would a normal function:
PHP Code:
myFunction();
In Object-Orientated Programming, functions are also known as Methods.