if statement
Use the if statement to execute some code only if a specified condition is true.
Syntax
if (condition) code to be executed if condition is true;
The following example will output "Have a nice weekend!" if the current day is Friday:
The following example will output "Have a nice weekend!" if the current day is Friday:
<?php
$d=date("D");
if ($d=="Fri") echo "Have a nice weekend!";
?>
$d=date("D");
if ($d=="Fri") echo "Have a nice weekend!";
?>
The if...else Statement
Use the if....else statement to execute some code if a condition is true and another code if a condition is false.Syntax
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
else
echo "Have a nice day!";
?>
The if...elseif....else Statement
Syntax
<?php
$d=date("D");
if ($d=="Fri")
echo "Have a nice weekend!";
elseif ($d=="Sun")
echo "Have a nice Sunday!";
else
echo "Have a nice day!";
?>
_______________________________________________________________
The while Loop
The while loop executes a block of code while a condition is true.Syntax
while (condition)
{
code to be executed;
}
Example
<?php$i=1;
while($i<=5)
{
echo "The number is " . $i . "<br />";
$i++;
}
?>
Output:
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
The do...while Statement
<?php
Output:
for (init; condition; increment)
<?php
Output:
foreach ($array as $value)
<?php
Output:
ليست هناك تعليقات:
إرسال تعليق