Intro:Combining conditional statement in php

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.";
}
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值