php mysql 如何用php检查NULL列

Far*_*zad 1 php mysql arrays mysqli

如何NULL用php检查mysql列变量?

我的行表(示例):

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

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

我从表中获取数组:

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

但我的问题:

如何检查 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?

}
Run Code Online (Sandbox Code Playgroud)

更新(var_dump):

'country' => null
Run Code Online (Sandbox Code Playgroud)

小智 5

使用 is_null 或 === 运算符。

is_null($row['country'])
Run Code Online (Sandbox Code Playgroud)