PHP Example

Major or Minor By Using If Condition :- 

<?php

$age=9;

if($age>=18)
{
echo ” Major”;
}
else
{
echo “Minor”;
}

?>

 Discount Calculation Example :- 

<?php

$p=100;
$q=20;

if($q>=20)
{
$d=0.1;

$da=$p*$q*$d;
}
else
{
$d=0;

$da=$p*$q*$d;
}

$a=($p*$q);

$dta=$a-$da;

echo “<br>Total Amount:-“.$a;
echo “<br>Discount Amount:-“.$da;
echo “<br>Discount total Amount:-“.$dta;
?>

Employee Salary Calculation :-

<center><h1>
<?php

$name=”shree”;

$bsal=20000;

if($bsal>=35000)
{

$hra=$bsal*0.1;
$da=$bsal*0.2;

}
else
{
$hra=$bsal*0.05;
$da=$bsal*0.1;

}

$ts=$bsal+$hra+$da;

echo “<Br>Employee Basic Salary=”.$bsal;
echo “<Br>Employee Hra=”.$hra;
echo “<Br>Employee Da=”.$da;
echo “<Br>Employee Total Salary=”.$ts;

?>

 

Conditional Control Structure :-

PHP If…Else Statements:-

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

* if statement – use this statement to execute some code only if a specified condition is true

* if…else statement – use this statement to execute some code if a condition is true and another code if the condition is false

* if…elseif….else statement – use this statement to select one of several blocks of code to be executed

* switch statement – use this statement to select one of many blocks of code to be executed

Syntax:-

<?php

$name=”srikanth reddy”;
if ($name==”srikanth reddy”)
echo “Have a nice Day Mr Srikanth Reddy “;

?>

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:-

If (condition)
Code to be executed if condition is true;
else
Code to be executed if condition is false;

 
<php
$number_three = 3;

if ($number_three == 3)
{
echo “The if statement evaluated to true”;
}
else
{
echo “The if statement evaluated to false”;
}
?>
The if…elseif….else Statement:-Use the if….elseif…else statement to select one of several blocks of code to be executed.

 

 

PHP Control Structure

control structure :-

Determine the flow of control in program.

there are four types of control structurs. they are

 1. sequence c.s :-

are executed in the same order in which they appear in the program.

2.selection or decision control s :-

allow the computer to take a decision as which instruction or control is to be executed next.
3.Repitition or loop c.s :-

to execute the group of statements repeatedly.
4. case c.s :-

allow the computer to take a case as which instruction or control is to be executed next.

OR

PHP Control Structure:-

1. Conditional Control Structure
2. Iterative Control Structure

Sno                 This Expression                            Meaning

1                         x==y                                           x is equal to y

2                        !x=y                                            x is not equal to y

3                        x<y                                             x is less than y

4                        x>y                                              x is greater than y

5                        x<=y                                            x is less than or equal to y

6                        x>=y                                            x is greater than or equal to y

 

PHP Student Marksheet Example

<center><h1>
<?php

$name=”shree”;
$regno=1;

$s1=40;
$s2=20;
$s3=30;

$t=$s1+$s2+$s3;
$p=$t/3;

if($p>=60)
{
echo ” first division “;
}
if($p>=50 and $p<60)
{
echo ” Second division “;
}
if($p>=40 and $p<50)
{
echo ” Third division “;

}

if($p<40)
{
echo ” fail”;

}

 

echo “<br>”;
if($s1>=35 and $s2>=35 and $s3>=35)
{
$r=”pass”;
}
else
{
$r=”fail”;
}

echo $r;
echo $t;
echo $p;

?>