1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

isset()とempty()

Last updated at Posted at 2015-06-05

どっちがどっちだっけってなるからメモ。

isset()

isset
$value = "はらへりむし";
$null = null;
var_dump(isset($value));  //true
var_dump(isset($name));   //false
var_dump(isset($null));   //false

変数がある、nullでない → true
変数がない、またはnull → false

empty()

empty
$value1 = "";
var_dump(isset($value1));  //true

$value2 = 0;
var_dump(isset($value2));   //true

$value3 = null;
var_dump(isset($value3));   //true

$value4 = "ほわた";
var_dump(isset($value4));   //false

var_dump(isset($value5));   //true

変数があり、「""」「0」「null」が入っている   → true
変数がない                   → true
変数があり、値が入っている           → false


変数があるのを調べる→isset()
変数がないのを調べる→empty()

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?