Jennifer
Jennifer

Reputation: 1852

Novice: Cakephp2 conditions

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?

Upvotes: 0

Views: 69

Answers (2)

Zakaria Wahabi
Zakaria Wahabi

Reputation: 213

if( $data[0]['data'] == 0 ){ //equal to zero

}

OR

if( $data[0]['data'] != 0 ){ //Not equal to zero

}else{ // equal to zero

}

Upvotes: 1

MikeBrown
MikeBrown

Reputation: 71

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.

Upvotes: 1

Related Questions