Decision Control in PHP
Decision Control Statement
Php has same decision control statements as other languages:
-
The “if” statement.
-
The “if-else” statement.
-
The “if-else if –else” statement.
-
The “switch” statement .
- Php “if” Statement
-
Syntax
-
if (condition)
{
// statement to run
}
-
Example
-
<?php
$username="sachin";
if($username=="sachin")
echo "Username valid";
else
echo "Username invalid";
?> - Php “if-else” Statement
-
Syntax
-
if (condition)
{
//code to be executed if condition is true;
}
else
{
//code to be executed if condition is false;
} -
Example
-
<?php
$t=date("H");
if ($t<“20")
{
echo "Have a good day!";
}
else
{
echo "Have a good night!";
}
?>