超市折扣如何最大折扣问题PHP求助

来源:6-2 PHP条件结构之if…else…

慕粉4098010

2016-10-03 15:00

怎么在生日 和  普通折扣中最大

写回答 关注

4回答

  • 慕斯2523272
    2017-03-28 09:28:12

    http://img.mukewang.com/58d9bc0e0001a0cf05210414.jpg

    上面的代码太多了吧

  • 无无法师
    2016-10-19 09:30:23
    //你的问题要用switch语句,还没学,代码和图示如下:
    <?php
    header("Content-type: text/html; charset=utf-8");
        date_default_timezone_set('Asia/ShangHai');
        $today = date('m-d',time());//获取当天日期
        $birthday = "02-14";//生日
        $money=2000;
        $discount;
        switch($money){
        case($money>=1500): //满1500以上的75折
            $discount=0.75;
            break;
        case($today==$birthday):  //今天生日8折
            $discount=0.8;
            break;
        case($money>=500):  //满500不满1500的95折
            $discount=0.95;
            break;
        default:
            $discount=1;
            break;
        }
        $money=$money*$discount;
     
        echo $money;
    ?>

    http://img.mukewang.com/5806ccac0001b64002910153.jpg

  • 慕粉4098010
    2016-10-03 20:47:24

    .123313

  • _我们在长大_0
    2016-10-03 15:23:22
    <?php
        date_default_timezone_set('Asia/ShangHai');
        $today = date('m-d',time());//获取当天日期
    	$birthday = "02-14";//生日
        $money=2000;
        $discount;
        if($today==$birthday)  //今天生日8折
        {
        $discount=0.8;
        }
        if($money>=500&&$money<1500)  //满500不满1500的95折
        {
            $discount=0.95;
        }
        if($money>=1500)  //满1500以上的75折
        {
            $discount=0.75;
        }
        else  //其他的均不打折
       {
            $discount=1;
       }
        
        $money=$money*$discount;
        
    
    	echo $money;
    ?>

    生日那天,满1500

    慕粉4098...

    我的意思是 如果 那天我生日,我没买超过1500,能8折结算。超过1500我就按照75结算

    2016-10-03 15:31:53

    共 2 条回复 >

PHP入门篇

PHP入门教程轻松学习,行业大牛帮您快速掌握PHP编程基础知识。

456326 学习 · 6575 问题

查看课程

相似问题