$record['field'] = null;
if (isset($record['field']) || is_null($record['field'])) {
// When $record['field'] is set and not null, OR, when $record['field'] = null
// Basically, when $record['field'] is defined as $record['field'] = whatever, even null.
} else {
// When $record['field'] is not defined at all, not even null
}
我的目的是检查是否定义了$record['field']
,甚至是null
。
但是,每次$record['field']
都没有设置(例如注释掉$ record [' field'] = null;),它会给我这个错误:
Undefined index: field
如果有人会问,这是因为当NULL值变得有意义时,例如在SQL查询中为时间戳列分配NULL值会使MySQL使用当前时间戳更新它。
我能做到这一点吗?