回答編集履歴
1
等価の式を分かりやすく対比で記載
answer
CHANGED
@@ -9,18 +9,19 @@
|
|
9
9
|
|
10
10
|
(2) の場合は、$foo が NULL の場合のみ
|
11
11
|
if の中身が実行されます。
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
余談ですが、下記が同じ挙動を返します。
|
12
16
|
|
17
|
+
(1)
|
13
|
-
|
18
|
+
```PHP
|
14
|
-
isset と is_null は正反対の結果を返しはしますが、
|
15
|
-
|
19
|
+
if ($foo)
|
20
|
+
if (!empty($foo))
|
21
|
+
```
|
16
22
|
|
23
|
+
(2)
|
17
24
|
```PHP
|
18
|
-
$x = 0; // isset($x) === true is_null($x) === false
|
19
|
-
$x = 1; // isset($x) === true is_null($x) === false
|
20
|
-
$x = ""; // isset($x) === true is_null($x) === false
|
21
|
-
|
25
|
+
if (isset($foo))
|
22
|
-
$x = true; // isset($x) === true is_null($x) === false
|
23
|
-
$x = false; // isset($x) === true is_null($x) === false
|
24
|
-
$x = []; // isset($x) === true is_null($x) === false
|
25
|
-
|
26
|
+
if (!is_null($foo))
|
26
27
|
```
|