Archive for the 'php basic' Category

Adding parameters in PHP Function

Adding parameters in PHP Function
Our first function writedate() is a very simple function. It only writes a static string.
To add more functionality to a function, we can add parameters. A parameter is just like a variable.
You may have noticed the parentheses after the function name, like: writedate(). The parameters are specified inside the [...]

PHP Functions

Create a PHP Function
function is a block of code that can be executed whenever we need it.
Creating PHP functions:

All functions start with the word “function()”
Name the function – It should be possible to understand what the function does by its name. The name can start with a letter or underscore (not a number)
Add [...]

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 [...]