dor2p0520 2014-04-30 13:27
浏览 38

多功能返回

Total newbie to php with problem. Here is function that calulate if value is between ex. 0,00 and 1.500,00 then discount number is 8

function wpsc_cart_discount_number(){
    global $wpsc_cart;
    if   ($total >= 0000 && $total < 1500) {
        return $discount->wpsc_cart_discount_number = '8';
    }   if ($total >= 1500 && $total < 3000) {
        return $discount->wpsc_cart_discount_number = '11';
    }   if ($total >= 3000 && $total < 7000) {
        return $discount->wpsc_cart_discount_number = '13';
    }  if ($total >= 7000 && $total < 10000) {
        return $discount->wpsc_cart_discount_number = '16';
    }  if ($total >= 10000) {
        return $discount->wpsc_cart_discount_number = '18';
    }
}

When i call this function it keep returning only value of "8" and not other what is wrong here?

Please help

Thanks

  • 写回答

2条回答 默认 最新

  • dongyanjing5975 2014-04-30 13:34
    关注

    Based on the fact, that you do not have a local $total variable in your function, it is undefined. By the flexible error handling of PHP, this would be only a notice, not an error. An undefined value is treated as 0 when compared to integers, therefore the first condition will be always be true.

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程