【问题标题】:php mysql how to check NULL column with phpphp mysql如何用php检查NULL列
【发布时间】:2017-10-30 02:02:28
【问题描述】:

如何用php检查mysqlNULL列变量?

我的行表(示例):

1 ---- james ------ italy

2 ---- joyee ------ NULL

我从表中获取数组:

$rows[0] = array('name' => 'james', 'country' => 'italy');
$rows[1] = array('name' => 'joyee', 'country' => NULL);

但我的问题:

如何检查NULL数组元素:

foreach($rows as $row) {

     if ($row['country'] == NULL) echo "country is null"; // not working
     if ($row['country'] == '') echo "country is null"; // not working
     if (is_null($row['country'])) echo "country is null"; // not working
     if (empty($row['country'])) echo "country is null"; // not working
     // what is  solution? how to check null?

}

更新(var_dump):

'country' => null

【问题讨论】:

  • 试试小写的null。
  • 你能用var_dump($rows[1])更新你的帖子吗?
  • PHP Check for NULL的可能重复
  • @NigelRen 不工作
  • @SahilGulati 更新了!

标签: php mysql arrays mysqli


【解决方案1】:

使用 is_null 或 === 运算符。

is_null($row['country'])

【讨论】:

    猜你喜欢
    • 2012-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    • 2015-04-08
    • 2014-12-29
    • 1970-01-01
    相关资源
    最近更新 更多