{"id":749,"date":"2025-01-05T22:26:17","date_gmt":"2025-01-05T14:26:17","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=749"},"modified":"2025-01-05T22:26:17","modified_gmt":"2025-01-05T14:26:17","slug":"php-%e4%b8%ad%e7%9a%84isset%e6%80%8e%e4%b9%88%e4%bd%bf%e7%94%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/01\/05\/php-%e4%b8%ad%e7%9a%84isset%e6%80%8e%e4%b9%88%e4%bd%bf%e7%94%a8%ef%bc%9f\/","title":{"rendered":"PHP \u4e2d\u7684isset()\u600e\u4e48\u4f7f\u7528\uff1f"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u5728 PHP \u4e2d\uff0c<code>isset()<\/code> \u662f\u4e00\u4e2a\u7528\u6765\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u5df2\u7ecf\u8bbe\u7f6e\u5e76\u4e14\u4e0d\u662f <code>null<\/code> \u7684\u51fd\u6570\u3002\u5b83\u7684\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>isset($var);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c <code>$var<\/code> \u5b58\u5728\u5e76\u4e14\u4e0d\u662f <code>null<\/code>\uff0c\u5219\u8fd4\u56de <code>true<\/code>\u3002<\/li>\n\n\n\n<li>\u5982\u679c <code>$var<\/code> \u4e0d\u5b58\u5728\u6216\u4e3a <code>null<\/code>\uff0c\u5219\u8fd4\u56de <code>false<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f8b\u5b50 1\uff1a\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u8bbe\u7f6e<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>$var = \"Hello, world!\";\nif (isset($var)) {\n    echo \"\u53d8\u91cf\u5df2\u8bbe\u7f6e\u5e76\u4e14\u4e0d\u662f null\";\n} else {\n    echo \"\u53d8\u91cf\u672a\u8bbe\u7f6e\u6216\u4e3a null\";\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u53d8\u91cf\u5df2\u8bbe\u7f6e\u5e76\u4e14\u4e0d\u662f null<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f8b\u5b50 2\uff1a\u68c0\u67e5\u6570\u7ec4\u4e2d\u7684\u952e\u662f\u5426\u5b58\u5728<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>$array = array(\"name\" =&gt; \"John\", \"age\" =&gt; 25);\nif (isset($array&#91;'name'])) {\n    echo \"name \u952e\u5b58\u5728\u5e76\u4e14\u4e0d\u662f null\";\n} else {\n    echo \"name \u952e\u4e0d\u5b58\u5728\u6216\u4e3a null\";\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>name \u952e\u5b58\u5728\u5e76\u4e14\u4e0d\u662f null<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f8b\u5b50 3\uff1a\u68c0\u67e5 <code>null<\/code> \u503c<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>$var = null;\nif (isset($var)) {\n    echo \"\u53d8\u91cf\u5df2\u8bbe\u7f6e\u5e76\u4e14\u4e0d\u662f null\";\n} else {\n    echo \"\u53d8\u91cf\u672a\u8bbe\u7f6e\u6216\u4e3a null\";\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u53d8\u91cf\u672a\u8bbe\u7f6e\u6216\u4e3a null<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u6ce8\u610f\u4e8b\u9879\uff1a<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>isset()<\/code> \u53ef\u4ee5\u63a5\u53d7\u591a\u4e2a\u53c2\u6570\u3002\u5982\u679c\u591a\u4e2a\u53c2\u6570\u4e2d\u6709\u4efb\u4f55\u4e00\u4e2a\u662f\u672a\u8bbe\u7f6e\u6216\u4e3a <code>null<\/code>\uff0c\u5219\u8fd4\u56de <code>false<\/code>\u3002<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   $var1 = \"Hello\";\n   $var2 = null;\n   if (isset($var1, $var2)) {\n       echo \"\u90fd\u5df2\u8bbe\u7f6e\u5e76\u4e14\u4e0d\u662f null\";\n   } else {\n       echo \"\u81f3\u5c11\u6709\u4e00\u4e2a\u53d8\u91cf\u672a\u8bbe\u7f6e\u6216\u4e3a null\";\n   }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   \u81f3\u5c11\u6709\u4e00\u4e2a\u53d8\u91cf\u672a\u8bbe\u7f6e\u6216\u4e3a null<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><code>isset()<\/code> \u4e0d\u80fd\u68c0\u6d4b\u5e38\u91cf\u7684\u5b58\u5728\u3002\u5982\u679c\u4f60\u5c1d\u8bd5\u68c0\u6d4b\u4e00\u4e2a\u5e38\u91cf\uff0c\u6700\u597d\u4f7f\u7528 <code>defined()<\/code> \u51fd\u6570\u3002<\/li>\n\n\n\n<li><code>isset()<\/code> \u8fd4\u56de <code>false<\/code> \u5bf9\u4e8e\u7a7a\u5b57\u7b26\u4e32 (<code>\"\"<\/code>)\u3001<code>0<\/code> \u6216 <code>false<\/code>\uff0c\u4f46\u8fd9\u4e9b\u503c\u662f\u5408\u6cd5\u7684\uff08\u5e76\u4e14\u4e0d\u662f <code>null<\/code>\uff09\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>   $var = \"\";\n   if (isset($var)) {\n       echo \"\u53d8\u91cf\u5df2\u8bbe\u7f6e\u5e76\u4e14\u4e0d\u662f null\";\n   } else {\n       echo \"\u53d8\u91cf\u672a\u8bbe\u7f6e\u6216\u4e3a null\";\n   }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   \u53d8\u91cf\u5df2\u8bbe\u7f6e\u5e76\u4e14\u4e0d\u662f null<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u603b\u7ed3\u6765\u8bf4\uff0c<code>isset()<\/code> \u662f\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u5b58\u5728\u5e76\u4e14\u4e0d\u4e3a <code>null<\/code> \u7684\u4e00\u4e2a\u975e\u5e38\u5e38\u7528\u7684\u51fd\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 PHP \u4e2d\uff0cisset() \u662f\u4e00\u4e2a\u7528\u6765\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u5df2\u7ecf\u8bbe\u7f6e\u5e76\u4e14\u4e0d\u662f null \u7684\u51fd\u6570\u3002\u5b83\u7684\u57fa\u672c\u8bed\u6cd5\u5982\u4e0b\uff1a  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[],"class_list":["post-749","post","type-post","status-publish","format-standard","hentry","category-php-"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/749","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=749"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/749\/revisions"}],"predecessor-version":[{"id":750,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/749\/revisions\/750"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}