简体   繁体   中英

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). 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. Even when I'm 100% sure $this->kamp is 387, 388 or 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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