Showing posts with label if else in php. Show all posts
Showing posts with label if else in php. Show all posts

Friday, 7 June 2013

Lesson 4- use of And-Or in If-Else

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";
?>

Sunday, 19 May 2013

Lesson 3- if-else statement in PHP


Use of If-else Statement

In the earlier example we calculated the hra and gross salary.

Suppose there is a policy of company that if salary is greater than 10000 then hra will be 5% of salary but if salary is less than 10000 then hra will be 10%
In this situation we will use if-else statement.

Syntax of if-else:-

If (condition)
{
          Logic when condition true
}
Else
{
          Logic when condition false
}