Archive for the 'php basic' Category

The foreach Statement

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.
foreach (array as value)
{
code to be executed;
}
Example
The following example […]

The for Statement

The for Statement
For statement is some Looping statements in PHP
The for statement is used when you know how many times you want to execute a statement or a list of statements.
for (initialization; condition; increment)
{
code to be executed;
}
Note: The for statement has three parameters. The first parameter initializes variables, the second parameter […]

The do…while Statement

Do…while is some Looping statements in PHP
The do…while statement will execute a block of code at least once - it then will repeat the loop as long as a condition is true.
do
{
code to be executed;
}
while (condition);
Example
The following example will increment the value of i at least once, and it will continue […]

while Statement

While is some Looping statements in PHP
The while statement will execute a block of code if and as long as a condition is true.
while (condition)
{code to be executed;}
Example
The following example demonstrates a loop that will continue to run as long as the variable i is less than, or equal to 5. i […]

PHP If…Else Statements

The if, elseif and else statements in PHP are used to perform different actions based on different conditions.
Conditional Statements
Very often when you write code, you want to perform different actions for different decisions.
You can use conditional statements in your code to do this.

if…else statement - use this statement if you want to execute […]