0% found this document useful (0 votes)
7 views

ConditionalStatement-in PHP

The document explains conditional statements in PHP, including simple if, if-else, else if, and switch statements. Each type is illustrated with example code that demonstrates how to execute different actions based on various conditions. The examples cover scenarios for comparing numbers and categorizing age groups.

Uploaded by

SANJEET KUMAR
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

ConditionalStatement-in PHP

The document explains conditional statements in PHP, including simple if, if-else, else if, and switch statements. Each type is illustrated with example code that demonstrates how to execute different actions based on various conditions. The examples cover scenarios for comparing numbers and categorizing age groups.

Uploaded by

SANJEET KUMAR
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Conditional statements in PHP:

Conditional statements are used to perform different actions based on different conditions.

simple if : statement - executes some code if one condition is true


program:
<!DOCTYPE html>
<html>
<body>
<?php
$a=20;
if($a <50)
{
echo "a is greater than 50 <BR>";
}
echo " default statement block"
?>
</body>
</html>

if else statements: executes some code if a condition is true and another code if that
condition is false

program:
<!DOCTYPE html>
<html>
<body>
<?php
$a=20;
$b=10;
if($a>$b) // condition block
{
echo "a is greater than b.<BR>"; // true statement block block
}
else
{
echo "b is greater than a.";// false statement block
}
?>
</body>
</html>
else if else: - executes different codes for more than two conditions

program:
<!DOCTYPE html>
<html>
<body>
<?php
$age=65;
if($age<18)
{
echo "You are child";
}
elseif($age>=18 && $age<50)
{
echo "You are adult";
}
else
{
echo "You are senior citizen";
}
?>
</body>
</html>

Switch statement: selects one of many blocks of code to be executed

program:

<!DOCTYPE html>
<html>
<body>
<?php
$age=71;
switch($age)
{
case ($age<18):
echo "You are child.";
break;
case ($age>=18 && $age<50):
echo "You are adult.";
break;
case ($age>=50 && $age<=70):
echo "You are senior citizen.";
break;
case ($age>70):
echo "You are super senior citizen.";
break;
default:
echo "you are in default block. Please provide proper input.";
}
?>
</body>
</html>

You might also like