{"id":1077,"date":"2019-04-07T19:34:26","date_gmt":"2019-04-07T11:34:26","guid":{"rendered":"https:\/\/freesilo.com\/?p=1077"},"modified":"2019-04-07T19:34:26","modified_gmt":"2019-04-07T11:34:26","slug":"php%e4%b8%ad%e5%88%a4%e6%96%ad%e5%8f%98%e9%87%8f%e4%b8%ba%e7%a9%ba%e7%9a%84%e5%87%a0%e7%a7%8d%e6%96%b9%e6%b3%95%e5%b0%8f%e7%bb%93","status":"publish","type":"post","link":"https:\/\/freesilo.com\/?p=1077","title":{"rendered":"PHP\u4e2d\u5224\u65ad\u53d8\u91cf\u4e3a\u7a7a\u7684\u51e0\u79cd\u65b9\u6cd5\u5c0f\u7ed3"},"content":{"rendered":"<blockquote><p>\u5224\u65ad\u53d8\u91cf\u4e3a\u7a7a\uff0c\u5728\u8bb8\u591a\u573a\u5408\u90fd\u4f1a\u7528\u5230\uff0c\u540c\u65f6\u81ea\u5df1\u548c\u8bb8\u591a\u65b0\u624b\u4e00\u6837\u4e5f\u7ecf\u5e38\u4f1a\u72af\u4e00\u4e9b\u9519\u8bef\uff0c\u6240\u4ee5\u81ea\u5df1\u6574\u7406\u4e86\u4e00\u4e0bPHP\u4e2d\u4e00\u4e9b\u5e38\u7528\u7684\u3001\u5224\u65ad\u53d8\u91cf\u4e3a\u7a7a\u7684\u65b9\u6cd5<\/p><\/blockquote>\n<p><strong>1. isset\u529f\u80fd\uff1a\u5224\u65ad\u53d8\u91cf\u662f\u5426\u88ab\u521d\u59cb\u5316<\/strong><\/p>\n<p>\u8bf4\u660e\uff1a\u5b83\u5e76\u4e0d\u4f1a\u5224\u65ad\u53d8\u91cf\u662f\u5426\u4e3a\u7a7a\uff0c\u5e76\u4e14\u53ef\u4ee5\u7528\u6765\u5224\u65ad\u6570\u7ec4\u4e2d\u5143\u7d20\u662f\u5426\u88ab\u5b9a\u4e49\u8fc7<br \/>\n\u6ce8\u610f\uff1a\u5f53\u4f7f\u7528isset\u6765\u5224\u65ad\u6570\u7ec4\u5143\u7d20\u662f\u5426\u88ab\u521d\u59cb\u5316\u8fc7\u65f6\uff0c\u5b83\u7684\u6548\u7387\u6bd4array_key_exists\u9ad84\u500d\u5de6\u53f3<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$a = '';\r\n$a&#x5B;'c'] = '';\r\nif (!isset($a)) echo '$a \u672a\u88ab\u521d\u59cb\u5316' . &quot;&quot;;\r\nif (!isset($b)) echo '$b \u672a\u88ab\u521d\u59cb\u5316' . &quot;&quot;;\r\nif (isset($a&#x5B;'c'])) echo '$a \u5df2\u7ecf\u88ab\u521d\u59cb\u5316' . &quot;&quot;;\r\n\/\/ \u663e\u793a\u7ed3\u679c\u4e3a\r\n\/\/ $b \u672a\u88ab\u521d\u59cb\u5316\r\n\/\/ $a \u5df2\u7ecf\u88ab\u521d\u59cb\u5316\r\n<\/pre>\n<p><strong>2. empty\u529f\u80fd\uff1a\u68c0\u6d4b\u53d8\u91cf\u662f\u5426\u4e3a&#8221;\u7a7a&#8221;<\/strong><\/p>\n<p>\u8bf4\u660e\uff1a\u4efb\u4f55\u4e00\u4e2a\u672a\u521d\u59cb\u5316\u7684\u53d8\u91cf\u3001\u503c\u4e3a 0 \u6216 false \u6216 \u7a7a\u5b57\u7b26\u4e32&#8221;&#8221; \u6216 null\u7684\u53d8\u91cf\u3001\u7a7a\u6570\u7ec4\u3001\u6ca1\u6709\u4efb\u4f55\u5c5e\u6027\u7684\u5bf9\u8c61\uff0c\u90fd\u5c06\u5224\u65ad\u4e3aempty==true<br \/>\n\u6ce8\u610f1\uff1a\u672a\u521d\u59cb\u5316\u7684\u53d8\u91cf\u4e5f\u80fd\u88abempty\u68c0\u6d4b\u4e3a&#8221;\u7a7a&#8221;<br \/>\n\u6ce8\u610f2\uff1aempty\u53ea\u80fd\u68c0\u6d4b\u53d8\u91cf\uff0c\u800c\u4e0d\u80fd\u68c0\u6d4b\u8bed\u53e5<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$a = 0;\r\n$b = '';\r\n$c = array();\r\nif (empty($a)) echo '$a \u4e3a\u7a7a' . &quot;&quot;;\r\nif (empty($b)) echo '$b \u4e3a\u7a7a' . &quot;&quot;;\r\nif (empty($c)) echo '$c \u4e3a\u7a7a' . &quot;&quot;;\r\nif (empty($d)) echo '$d \u4e3a\u7a7a' . &quot;&quot;;\r\n<\/pre>\n<p><strong>3. var == null\u529f\u80fd\uff1a\u5224\u65ad\u53d8\u91cf\u662f\u5426\u4e3a&#8221;\u7a7a&#8221;<\/strong><\/p>\n<p>\u8bf4\u660e\uff1a\u503c\u4e3a 0 \u6216 false \u6216 \u7a7a\u5b57\u7b26\u4e32&#8221;&#8221; \u6216 null\u7684\u53d8\u91cf\u3001\u7a7a\u6570\u7ec4\u3001\u90fd\u5c06\u5224\u65ad\u4e3a null<br \/>\n\u6ce8\u610f\uff1a\u4e0eempty\u7684\u663e\u8457\u4e0d\u540c\u5c31\u662f\uff1a\u53d8\u91cf\u672a\u521d\u59cb\u5316\u65f6 var == null \u5c06\u4f1a\u62a5\u9519\u3002<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$a = 0;\r\n$b = array();\r\nif ($a == null) echo '$a \u4e3a\u7a7a' . &quot;&quot;;\r\nif ($b == null) echo '$b \u4e3a\u7a7a' . &quot;&quot;;\r\nif ($c == null) echo '$b \u4e3a\u7a7a' . &quot;&quot;;\r\n\/\/ \u663e\u793a\u7ed3\u679c\u4e3a\r\n\/\/ $a \u4e3a\u7a7a\r\n\/\/ $b \u4e3a\u7a7a\r\n\/\/ Undefined variable: c\r\n<\/pre>\n<p><strong>4. is_null\u529f\u80fd\uff1a\u68c0\u6d4b\u53d8\u91cf\u662f\u5426\u4e3a&#8221;null&#8221;<\/strong><\/p>\n<p>\u8bf4\u660e\uff1a\u5f53\u53d8\u91cf\u88ab\u8d4b\u503c\u4e3a&#8221;null&#8221;\u65f6\uff0c\u68c0\u6d4b\u7ed3\u679c\u4e3atrue<br \/>\n\u6ce8\u610f1\uff1anull\u4e0d\u533a\u5206\u5927\u5c0f\u5199\uff1a$a = null; $a = NULL \u6ca1\u6709\u4efb\u4f55\u533a\u522b<br \/>\n\u6ce8\u610f2\uff1a\u4ec5\u5728\u53d8\u91cf\u7684\u503c\u4e3a&#8221;null&#8221;\u65f6\uff0c\u68c0\u6d4b\u7ed3\u679c\u624d\u4e3atrue\uff0c0\u3001\u7a7a\u5b57\u7b26\u4e32\u3001false\u3001\u7a7a\u6570\u7ec4\u90fd\u68c0\u6d4b\u4e3afalse<br \/>\n\u6ce8\u610f3\uff1a\u53d8\u91cf\u672a\u521d\u59cb\u5316\u65f6\uff0c\u7a0b\u5e8f\u5c06\u4f1a\u62a5\u9519<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$a = null;\r\n$b = false;\r\nif (is_null($a)) echo '$a \u4e3aNULL' . &quot;&quot;;\r\nif (is_null($b)) echo '$b \u4e3aNULL' . &quot;&quot;;\r\nif (is_null($c)) echo '$c \u4e3aNULL' . &quot;&quot;;\r\n\/\/ \u663e\u793a\u7ed3\u679c\u4e3a\r\n\/\/ $a \u4e3aNULL\r\n\/\/ Undefined variable: c\r\n<\/pre>\n<p><strong>5. var === null\u529f\u80fd\uff1a\u68c0\u6d4b\u53d8\u91cf\u662f\u5426\u4e3a&#8221;null&#8221;\uff0c\u540c\u65f6\u53d8\u91cf\u7684\u7c7b\u578b\u4e5f\u5fc5\u987b\u662f&#8221;null&#8221;<\/strong><\/p>\n<p>\u8bf4\u660e\uff1a\u5f53\u53d8\u91cf\u88ab\u8d4b\u503c\u4e3a&#8221;null&#8221;\u65f6\uff0c\u540c\u65f6\u53d8\u91cf\u7684\u7c7b\u578b\u4e5f\u662f&#8221;null&#8221;\u65f6\uff0c\u68c0\u6d4b\u7ed3\u679c\u4e3atrue<br \/>\n\u6ce8\u610f1\uff1a\u5728\u5224\u65ad\u4e3a&#8221;null&#8221;\u4e0a\uff0c\u5168\u7b49\u4e8e\u548cis_null\u7684\u4f5c\u7528\u76f8\u540c<br \/>\n\u6ce8\u610f2\uff1a\u53d8\u91cf\u672a\u521d\u59cb\u5316\u65f6\uff0c\u7a0b\u5e8f\u5c06\u4f1a\u62a5\u9519<\/p>\n<p><strong>\u603b\u7ed3PHP\u4e2d\uff0c&#8221;NULL&#8221; \u548c &#8220;\u7a7a&#8221; \u662f2\u4e2a\u6982\u5ff5\u3002<\/strong><\/p>\n<p>isset\u00a0 \u4e3b\u8981\u7528\u6765\u5224\u65ad\u53d8\u91cf\u662f\u5426\u88ab\u521d\u59cb\u5316\u8fc7<br \/>\nempty\u00a0 \u53ef\u4ee5\u5c06\u503c\u4e3a &#8220;\u5047&#8221;\u3001&#8221;\u7a7a&#8221;\u3001&#8221;0&#8243;\u3001&#8221;NULL&#8221;\u3001&#8221;\u672a\u521d\u59cb\u5316&#8221; \u7684\u53d8\u91cf\u90fd\u5224\u65ad\u4e3aTRUE<br \/>\nis_null\u00a0 \u4ec5\u628a\u503c\u4e3a &#8220;NULL&#8221; \u7684\u53d8\u91cf\u5224\u65ad\u4e3aTRUE<br \/>\nvar == null\u00a0 \u628a\u503c\u4e3a &#8220;\u5047&#8221;\u3001&#8221;\u7a7a&#8221;\u3001&#8221;0&#8243;\u3001&#8221;NULL&#8221; \u7684\u53d8\u91cf\u90fd\u5224\u65ad\u4e3aTRUE<br \/>\nvar === null\u00a0 \u4ec5\u628a\u503c\u4e3a &#8220;NULL&#8221; \u7684\u53d8\u91cf\u5224\u65ad\u4e3aTRUE<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u5728\u5224\u65ad\u4e00\u4e2a\u53d8\u91cf\u662f\u5426\u771f\u6b63\u4e3a&#8221;NULL&#8221;\u65f6\uff0c\u5927\u591a\u4f7f\u7528 is_null\uff0c\u4ece\u800c\u907f\u514d&#8221;false&#8221;\u3001&#8221;0&#8243;\u7b49\u503c\u7684\u5e72\u6270\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5224\u65ad\u53d8\u91cf\u4e3a\u7a7a\uff0c\u5728\u8bb8\u591a\u573a\u5408\u90fd\u4f1a\u7528\u5230\uff0c\u540c\u65f6\u81ea\u5df1\u548c\u8bb8\u591a\u65b0\u624b\u4e00\u6837\u4e5f\u7ecf\u5e38\u4f1a\u72af\u4e00\u4e9b\u9519\u8bef\uff0c\u6240\u4ee5&#8230;<br \/><a class=\"read-more-button\" href=\"https:\/\/freesilo.com\/?p=1077\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1077","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/1077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1077"}],"version-history":[{"count":1,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/1077\/revisions"}],"predecessor-version":[{"id":1078,"href":"https:\/\/freesilo.com\/index.php?rest_route=\/wp\/v2\/posts\/1077\/revisions\/1078"}],"wp:attachment":[{"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/freesilo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}