In database, Student_id is containing 0 value. I want to check it in if condition, but required result is not achieved. I have tried following scenarios in if condition:
if(is_null($item['student_id'])) {}
if($item['student_id'] === 0){}
if($item['student_id'] == 0){}
if(intval($item['student_id']) == 0){}
if(strval("$item['student_id']") == "0"){}
Note: Currently Iam trying to print some message in if conditions. But on student_id = 0, nothing is printed. If student_id is other than 0, then print is working fine.
Can some one guide me what Iam doing wrong and how it can be rectified.
I have added var_dump
array
'_id' =>
object(MongoId)[2]
public '$id' => string '50906d7fa3c412bb040eb577' (length=24)
'student_id' => int 0
'type' => string 'exam' (length=4)
'score' => float 54.653543636265
array
'_id' =>
object(MongoId)[6]
public '$id' => string '50906d7fa3c412bb040eb578' (length=24)
'student_id' => int 0
'type' => string 'quiz' (length=4)
'score' => float 31.950044967421
array
'_id' =>
object(MongoId)[2]
public '$id' => string '50906d7fa3c412bb040eb579' (length=24)
'student_id' => int 0
'type' => string 'homework' (length=8)
'score' => float 14.850457681164
This should work unless your value is not really 0.
Else another way that could work is this, you almost had it:
But then again, make sure you REALLY have a 0 in there… can you var_dump $item for us just to make sure?