开发者

Basic PHP logic problem

开发者 https://www.devze.com 2022-12-30 04:24 出处:网络
$this->totplpremium is 2400 $this->minpremiumq is 800 So why would this ever return true?开发者_如何学编程!
$this->totplpremium is 2400
$this->minpremiumq is 800

So why would this ever return true?开发者_如何学编程!

if ($this->totplpremium < $this->minpremiumq){

The figures are definitely correct and I am definitely using the 'less than' symbol. I can't work it out.


Maybe there's some kind of conversion problem. Try use

var_dump($this->totplpremium);
var_dump($this->minpremiumq);
if ($this->totplpremium < $this->minpremiumq){
  ...
}

to see if the datatypes are allright

EDIT: There are tools that enables you to debug your code more easily than using debugging outputs - http://xdebug.org/ (an extension for PHP that enables you debugging) and http://en.wikipedia.org/wiki/PHPEd (It's commercial. I don't know if there's an alternative.)


Try wrapping the 'numbers' with intval:

if (intval($this->totplpremium) < intval($this->minpremiumq)){
//...
}

If this works as expected then you really need to check what types totplpremium and minpremiumq are by using gettype, for example:

print(gettype($this->totplpremium));
print(gettype($this->minpremiumq));

With that info you should be able to pinpoint your error.


As an alphabetical comparison, the following statement is true:

"800" > "2400"

(because 8 is greater than 2)


<?php

$totplpremium="2400 ";
$minpremiumq="800";

var_dump(($totplpremium < $minpremiumq)?true:false);
var_dump(((int)$totplpremium < (int)$minpremiumq)?true:false);

?>

I'd guess you should either double check where these values come from OR make sure they are integers.

Good luck coding!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号