teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

等価の式を分かりやすく対比で記載

2016/12/13 12:33

投稿

MEBITUS
MEBITUS

スコア83

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
- $x = null; // isset($x) === false is_null($x) === true
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
- // 未定義 $x isset($x) === false is_null($x) === true
26
+ if (!is_null($foo))
26
27
  ```