如何处理数组中的null值

时间:2012-07-18 10:31:46

标签: php mysql

我有一个查询

  $sql="SELECT mstEmp.empname,mstEmp.cardno, InDate, dailyattendance.InTime,dailyattendance.OutTime, mstEmp.teamtype FROM mstEmp left JOIN dailyattendance ON (InDate BETWEEN '$from' AND '$to' )  AND (dailyattendance.HolderName = mstEmp.empname ) WHERE mstEmp.teamtype = '$chk' ORDER BY InDate DESC";

现在当我将它作为print_r($ row)运行时,它给出了数组为[0] = absbd [1] = 34 [2] = [3] = [4] = 现在我想[2]这是显示日期的日期,但它给了我垃圾值。

2 个答案:

答案 0 :(得分:1)

尝试这个......,

if(!is_null($var)){
    // Do ur stuff
}

参考is_null

答案 1 :(得分:0)

您可以明确检查null:

if($row[2] === null) {
    // Special behavior for null
] else {
    // Handle the date normally
}