-2
$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']
沒有被設置在所有(如註釋掉$紀錄[「場」] = NULL;),它給了我這個錯誤:
Undefined index: field
萬一有人會問,這是因爲當NULL值變得有意義時,例如在SQL查詢中爲timestamp列指定NULL值將使MySQL使用當前時間戳更新它。
什麼辦法可以做到這一點?
注意「未定義指數」是一個通知,而不是一個錯誤,你可以選擇,如果你想忽略它。 – IMSoP