LoginSignup
1
0

More than 3 years have passed since last update.

PHPでの「0」と「NULL」の比較について

Posted at

いろんなところで言われてますがPHPでの0NULLの比較には注意が必要です。(ハマった)

$hoge = 0;
var_dump($hoge == NULL); // bool(true)
var_dump($hoge === NULL); // bool(false)
var_dump(is_null($hoge)); // bool(false)

is_null()、もしくは型比較までやったほうが安全という学びでした。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0