You are here
Home > featured > PHP Cheatsheet

PHP Cheatsheet

PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft’s ASP. from w3schools

Example of several ways of Loop

Foreach Loop:
foreach ($array as $value) {
code to be executed;
}
example:
foreach($ArrayOfObject as $object)
{
}

For Loop:
for (initialization; condition; increment){
code to be executed;
}
example:
for($i = 0; $i < limit ; $i++)
{
code to be executed;
}

While Loop:
while (condition is true) {
code to be executed;
}
example:
while ($i < 10) {
code to be executed;
}

Do while Loops:
do {
code to be executed;
}
while (condition);
example:
do {
code to be executed;
}
while ($i < 10);

Leave a Reply

Top