You are on page 1of 7

Class: CO6I – A/B Academic Year: 2020-2021

Experiment – 2
Title: Write a PHP program to demonstrate the use of decision making
control structures using
a. If….else statement
b. If….elseif…..else statement
c. Switch statement
Roll No.:29 Name: Mehraan Khan

1. Aim: Write a PHP program to demonstrate the use of decision making control structures
using
a. If….else statement
b. If….elseif…..else statement
c. Switch statement

2. Resource Used:
Personal Computer, Windows XP or above operating system, XAMPP (PHP,
APACHE, MYSQL), Microsoft Word

3. Theory:
Program Code:
a. Write PHP script to check whether given number is even or odd using if--else
statement
<?php
{
$n = 4;
if($n % 2 == 0){
echo "Even";
}
else{
echo "Odd";
}
} ?>

b. Write PHP script to check whether number is positive, negative or zero using
if---elseif ---else statement
<?php
$n = 1;
if ($n > 0) {
echo "the number is positive";
}
elseif ($n < 0){
echo "the number is negative";
}
else {
echo "the number is 0";
}
?>
c. Write PHP script to display any month of the year using switch--case statement
<?php
$Month = "September";
switch ($Month) {
case 'January':
echo "The month is January";
break;
case 'February':
echo "The month is February";
break;
case 'March':
echo "The month is March";
break;
case 'April':
echo "The month is April";
break;
case 'May':
echo "The month is May";
break;
case 'july':
echo "The month is july";
break;
case 'August':
echo "The month is August";
break;
case 'September':
echo "The month is September";
break;
case 'October':
echo "The month is October";
break;case 'October':
echo "The month is November";
break;
default:
echo "The month is December";
break;
}
?>
2. Conclusion:

Hence we learned to write a PHP program to demonstrate the use of decision making control
structures using
a. If….else statement
b. If….elseif…..else statement
c. Switch statement

Page 1 of 1

You might also like