Hi I'm new to cakephp2 and mysql and I'm here to find some tips and help.
The problem is that I've set the value as 0 to store it in the database:
('data'=>0)
I made a function that will check if the data is zero or not like:
if($data[0]['data']===0).
I want to compare the data from the database that has been stored as the int with 0 , however, this does not work.
Sorry for my bad English, to make it simple I want to compare the data from the database with a int in cakephp2/php, if comparing with 0 should I use is_null,empty or use just === 0 for simple comparison?
You can check it like this:
if( (int) $data[0]['data'] === 0){
//your code here
}
As stated by Scopey in the comments you probably returned a string '0', not the integer 0.
if( $data[0]['data'] == 0 ){ //equal to zero
}
OR
if( $data[0]['data'] != 0 ){ //Not equal to zero
}else{ // equal to zero
}
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.