Category PHP
Solve the “Denied access” problem when using Wamp server 2 on Windows8
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 variable swapping without third party variable
variable swap without third party variable.
<?php
$a=10;
$b=20;
echo ” before swapping variables ”
echo $a;
echo $b;
$a=$a+$b; // $a=$a*$b;
$b=$a-$b; // $b=$a/$b;
$a=$a-$b; // $a=$a/$b;
echo ” after swapping variables ”
echo $a;
echo $b;
?>
PHP variable swaping Program with third party variable Example
variable swaping with third party variable
Eaxmple :-
<?php
$a=10;
$b=20;
echo ” before swapping variables ”
echo $a;
echo $b;
$t=$a;
$a=$b;
$b=$t;
echo ” After swapping variables ”
echo $a;
echo $b;
?>
PHP Simple Intrest Example
simple intrest
example :-
<?php
$p=5000;
$r=5;
$t=3;
$s=($p*%t*$r)/100;
$ta=$p+$s;
echo $p;
echo $s;
echo $ta;
?>
PHP Sum Of Given Numbers Example By using For Loop
<center><h1>
<?php
$sum=0;
for($n=1;$n<=5;$n=$n+1)
{
$sum=$sum+$n;
}
echo $sum;
?>
PHP For Loop Example
<center><h1>
<?php
for($n=1;$n<=100;$n=$n+1)
{
if($n%2==0)
{
echo”<br>”.$n;
if($n==20)
{
break;
}
}
}
?>
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;
?>