PHP loop

PHP loop

PHP – While loop:
while loops check for the expression. If it is evaluated to true, the subsequent statement is executed.

Example:

$ x=5;
While($x <=10)
{
    Echo x++;
}

PHP – For loop:
The for loops are similar to the for loop in C.

For ($x=1; $x<10l; $x++)
{
    Echo $x;
}

PHP for each – PHP for each works best only for arrays.

Syntax: here, the foreach loops over the array given by array_expression. On each loop, the value of the current element is assigned to $value and the internal array pointer is advanced by one.

Foreeach
{
    array_expression as $value
}
    Statement_to_execute

Example:

$arr = array(1, 2, 3, 4);
foreach ($arr as &$value)
{
    $value = $value * 2;
}
PHP function
PHP has around hundreds of inbuilt for functions which makes it a very powerful language.
PHP data types
PHP supports a number of fundamental basic data types, such as integers, floats, and strings.
PHP automatics type conversion
Automatic type conversion is essential when two differently typed variables are combined in an expression
Post your comment

You may like