PHP-if语句无法正常工作

灵能

我目前正在制作拍卖网站。为了确保人们的出价不会超出当前出价,我做了以下if陈述:

if(
    ($this->getHighestBid() < 50 && $this->getHighestBid() >= 0 && $bid > $this->getHighestBid()+0.50) ||
    ($this->getHighestBid() < 500 && $this->getHighestBid() >= 50 && $bid > $this->getHighestBid()+1) ||
    ($this->getHighestBid() < 1000 && $this->getHighestBid() >= 500 && $bid > $this->getHighestBid()+5) ||
    ($this->getHighestBid() < 5000 && $this->getHighestBid() >= 1000 && $bid > $this->getHighestBid()+10) ||
    ($this->getHighestBid() >= 5000 && $bid > $this->getHighestBid()+50)            
){
...
}

这样可以确保当前的最高出价在指定范围内时,您必须至少将价格提高指定的价格。我的问题是,它根本不允许我出价。有人知道这是怎么回事吗?

cra

您的代码似乎在我的测试中可以正常工作,听起来变量的类型不是数字类型(浮点型或整数),实际上是字符串或类似的奇怪类型。

确认:

var_dump($this->getHighestBid());

我想在写我的答案的同时添加一点,尽管您可能希望编辑您的代码以阅读更多内容:

function getMinimumBid() {
     $maxBid = (float)$this->getHighestBid();
     return $maxBid + $this->getBidIncrement();
}

function getBidIncrement() {
     $maxBid = (float)$this->getHighestBid();
     switch (true) {
          case $maxBid < 50:
              return 0.50;
          case $maxBid < 500:
              return 1;
          case $maxBid < 1000:
              return 5;
          case $maxBid < 5000:
              return 10;
          default:
              return 50;
     }
}

// ...
    if ($bid >= $this->getMinimumBid()) {
    }
// ...

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章