简体   繁体   English

将对象属性与OO PHP中的整数进行比较?

[英]Comparing Object Attributes to Integers in OO PHP?

I'm having a small problem. 我有一个小问题。 In a class called reservation that has an attribute called reserve , which in the database is a tinyint(4), and an attribute kamp, which is int(10). 在一个名为reserve的类中,该类具有一个称为reserve的属性,该属性在数据库中是tinyint(4)和一个属性kamp,它是int(10)。 I'm trying to do this: 我正在尝试这样做:

if ($this->kamp == 387 || $this->kamp == 388 || $this->kamp == 389) {
   $this->reserve = 0; 
} else { 
    $this->reserve = 1;
}

Now my problem is, the code ALWAYS jumps straight to the else bracket. 现在我的问题是,代码总是直接跳转到else括号。 Even when I'm 100% sure $this->kamp is 387, 388 or 389. 即使我100%确定$ this-> kamp是387、388或389。

Does this have anything to do with datatypes or am I missing something? 这与数据类型有关系吗,还是我缺少什么? I think the problem lies within this piece of code, since in my database there are objects showing up where reserve = 1 and the kamp is one of the three numbers I mentioned. 我认为问题出在这段代码中,因为在我的数据库中显示了对象,其中reserve = 1,kamp是我提到的三个数字之一。

Thanks! 谢谢!

i think this will work for you. 我认为这将为您工作。

$val = intval($this->kamp);

and then print or echo for result it will giving you value or not ? 然后打印或回显结果是否会为您带来价值?

let me know if i can help you more. 让我知道我是否可以帮助您更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM