Use of
“And” and “OR” in if –Else
When
we need to check more than one condition in if-else, then we use “And” and “OR” operator
in if else.
Use of “And”
When
we need that all condition must be true then we use “And” operator.
For Example
Let’s
take the previous example where we calculate gross salary. I am taking the same
example here but with some changes. If candidate salary is greater than 10000
and his dept is hr then his pf will be 5% but for other dept the pf will be 2%
with all salary.
Solution
of this program will be as follows:-
<?php
$sal=6000;
$dept="hr";
$hra;
$gross_sal=0;
if($sal>10000
and $dept="hr")
{
$hra=($sal*5)/100;
$gross_sal=$sal+$hra;
}
else
{
$hra=($sal*2)/100;
$gross_sal=$sal+$hra;
}
echo
" The Gross Salary is $gross_sal";
?>