【发布时间】: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 更新了!