PHP allows one conditional statement to be nested within another,to allow for more complex decision-marking.To illustrate this,consider the following listing:
<?php
//for employees with annual comp <=$1500
//those with a rating >=3 get a $5000 bonus
//everyone else gets a $3000 bonus
if($rating>=3){
if($salary<15000){
$bonus=5000;
}
}else{
if($salary<15000){
$bonus=3000;
}
}
?>
You can also combine conditional statements by using logical operators,such as the && or || operator.You learned about logical operators $$ || !.
Here the example of how these logical operators can be used with a conditional statement:
<?php
$year=2008;
//leap years are divisible by 400
//or by 4 but not 100
if (($year%400==0))||(($year%100!=0))&&($year%4==0){
echo "$year is a leap year.";
}else{
echo "$year is not a leap year.";
}
?>
<?php
//for employees with annual comp <=$1500
//those with a rating >=3 get a $5000 bonus
//everyone else gets a $3000 bonus
if($rating>=3){
if($salary<15000){
$bonus=5000;
}
}else{
if($salary<15000){
$bonus=3000;
}
}
?>
You can also combine conditional statements by using logical operators,such as the && or || operator.You learned about logical operators $$ || !.
Here the example of how these logical operators can be used with a conditional statement:
<?php
$year=2008;
//leap years are divisible by 400
//or by 4 but not 100
if (($year%400==0))||(($year%100!=0))&&($year%4==0){
echo "$year is a leap year.";
}else{
echo "$year is not a leap year.";
}
?>