{"id":419,"date":"2025-06-10T20:10:35","date_gmt":"2025-06-10T12:10:35","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/419.html"},"modified":"2025-06-10T20:10:35","modified_gmt":"2025-06-10T12:10:35","slug":"%e7%90%86%e8%a7%a3-php-%e4%b8%ad%e7%9a%84-null","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/419.html","title":{"rendered":"\u7406\u89e3 PHP \u4e2d\u7684 NULL"},"content":{"rendered":"<p><body><\/p>\n<h2>&#20171;&#32461;<\/h2>\n<p>&#22312;PHP&#20013;&#65292;<code>NULL<\/code>&#36825;&#26159;&#19968;&#20010;&#29305;&#27530;&#30340;&#25968;&#25454;&#31867;&#22411;&#65292;&#34920;&#31034;&#19968;&#20010;&#27809;&#26377;&#20540;&#30340;&#21464;&#37327;&#65307;&#29702;&#35299;&#20854;&#21547;&#20041;&#23545;&#20110;&#32534;&#20889;&#20581;&#22766;&#30340;&#24212;&#29992;&#31243;&#24207;&#33267;&#20851;&#37325;&#35201;&#12290;&#26412;&#25945;&#31243;&#36890;&#36807;&#36880;&#27493;&#22797;&#26434;&#30340;&#20363;&#23376;&#26469;&#35828;&#26126;&#20854;&#20351;&#29992;&#26041;&#27861;&#12290;<\/p>\n<h2>NULL&#30340;&#22522;&#26412;&#27010;&#24565;<\/h2>\n<p>&#24403;&#19968;&#20010;&#21464;&#37327;&#26410;&#36171;&#20540;&#26102;&#65292;&#23427;&#20250;&#33258;&#21160;&#34987;&#36171;&#20104;&#40664;&#35748;&#20540;&#12290;<code>NULL<\/code>&#22312;PHP&#20013;&#65292;<code>NULL<\/code>&#35813;&#21151;&#33021;&#19981;&#21306;&#20998;&#22823;&#23567;&#20889;&#65292;&#20063;&#23601;&#26159;&#35828;<code>null<\/code>&#22909;&#30340;&#65292;&#35831;&#21457;&#36865;&#20320;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<code>NULL<\/code>&#25110;&#32773;<code>Null<\/code>&#31561;&#20215;&#30340;&#12290;&#35753;&#25105;&#20204;&#26469;&#30475;&#30475;&#36825;&#20010;&#20363;&#23376;&#65306;<\/p>\n<pre><code>$var; \/\/ Declares a variable without initializing\nvar_dump($var); \/\/ Outputs NULL\n<\/code><\/pre>\n<p>&#25105;&#20204;&#20063;&#21487;&#20197;&#26126;&#30830;&#22320;&#20998;&#37197;&#12290;<code>NULL<\/code>&#36171;&#20540;&#32473;&#19968;&#20010;&#21464;&#37327;&#65306;<\/p>\n<pre><code>$var = NULL;\nvar_dump($var); \/\/ Outputs NULL\n<\/code><\/pre>\n<p>&#20026;&#20102;&#26816;&#26597;&#19968;&#20010;&#21464;&#37327;&#26159;&#21542;<code>NULL<\/code>&#35831;&#20351;&#29992;&#12290;<code>is_null()<\/code>&#21151;&#33021;&#65306;<\/p>\n<pre><code>$var = NULL;\nvar_dump(is_null($var)); \/\/ Outputs bool(true)\n<\/code><\/pre>\n<h2>&#26410;&#23450;&#20041;&#25110;&#26410;&#35774;&#32622;&#30340;&#21464;&#37327;<\/h2>\n<p>&#36890;&#36807;unset()&#20989;&#25968;&#21487;&#20197;&#21462;&#28040;&#19968;&#20010;&#21464;&#37327;&#30340;&#35774;&#32622;&#12290;<code>unset()<\/code>&#20063;&#23548;&#33268;&#20102;<code>NULL<\/code>&#20309;&#26102;&#34987;&#35775;&#38382;&#65306;<\/p>\n<pre><code>$var = 'PHP';\nunset($var);\nvar_dump($var); \/\/ Outputs NULL\n<\/code><\/pre>\n<p>&#35831;&#35760;&#20303;&#65292;&#26410;&#36171;&#20540;&#30340;&#21464;&#37327;&#21644;&#26410;&#21021;&#22987;&#21270;&#30340;&#21464;&#37327;&#22312;&#25968;&#20540;&#19978;&#26159;&#30456;&#21516;&#30340;&mdash;&mdash;&#23427;&#20204;&#37117;&#21253;&#21547;&#20160;&#20040;&#12290;<code>NULL<\/code>&#24050;&#32463;&#25910;&#21040;&#65292;&#35831;&#38382;&#26377;&#20160;&#20040;&#25105;&#21487;&#20197;&#24110;&#24537;&#30340;&#21527;&#65311;<\/p>\n<h2>&#22312;&#27604;&#36739;&#20013;&#65292;NULL&#34987;&#35270;&#20026;&#19968;&#20010;&#29305;&#27530;&#20540;&#12290;<\/h2>\n<p>&#19982;&#20043;&#30456;&#27604;<code>NULL<\/code>&#21478;&#19968;&#20010;&#39046;&#22495;&#29702;&#35299;&#20854;&#34892;&#20026;&#33267;&#20851;&#37325;&#35201;&#12290;&#35753;&#25105;&#20204;&#25506;&#32034;&#19968;&#19979;&#36825;&#20010;&#39046;&#22495;&#12290;<code>==<\/code>and &#26159;&#20013;&#25991;&#37324;&#30340;&ldquo;&#24182;&#19988;&rdquo;&#25110;&ldquo;&#32780;&#19988;&rdquo;&#30340;&#24847;&#24605;&#65292;&#29992;&#20110;&#36830;&#25509;&#24182;&#21015;&#30340;&#21477;&#23376;&#25110;&#30701;&#35821;&#12290;<code>===<\/code>Operators:<\/p>\n<pre><code>$var = NULL;\nvar_dump($var == NULL); \/\/ Outputs bool(true)\nvar_dump($var === NULL); \/\/ Outputs bool(true)\n$var = 0;\nvar_dump($var == NULL); \/\/ Outputs bool(true): 0 is 'equal' to NULL\nvar_dump($var === NULL); \/\/ Outputs bool(false): 0 is not identical to NULL\n<\/code><\/pre>\n<p>&#22312;&#20351;&#29992;&#26102;&#65292;&#35831;&#27880;&#24847;&#20197;&#19979;&#20107;&#39033;&#65306;<code>==<\/code>&#22909;&#30340;&#65292;&#35831;&#21457;&#36865;&#20320;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<code>NULL<\/code>&#23427;&#26159;&#34987;&#35748;&#20026;&#26159;&#31561;&#20110;&#38646;&#21644;&#19968;&#20010;&#31354;&#23383;&#31526;&#20018;&#12290;&#28982;&#32780;&#65292;&#26681;&#25454;&#24773;&#20917;&#30340;&#19981;&#21516;&#65292;&#23427;&#21487;&#20197;&#34920;&#31034;&#20026;0&#25110;&#8221;&#8221;&#12290;<code>===<\/code>&#23427;&#20204;&#24182;&#19981;&#23436;&#20840;&#30456;&#21516;&#65292;&#22240;&#20026;&#23427;&#20204;&#19981;&#26159;&#21516;&#19968;&#31867;&#22411;&#30340;&#12290;<\/p>\n<h2>&#22312;&#20989;&#25968;&#20013;&#65292;NULL &#36890;&#24120;&#34920;&#31034;&#31354;&#20540;&#25110;&#26410;&#23450;&#20041;&#30340;&#20540;&#12290;<\/h2>\n<p>&#22312;&#20989;&#25968;&#20013;&#65292;&#21464;&#37327;&#21487;&#20197;&#20316;&#20026;&#36820;&#22238;&#20540;&#36820;&#22238;&#12290;<code>NULL<\/code>&#26126;&#30830;&#22320;&#25110;&#38544;&#21547;&#22320;&#36820;&#22238;&#20540;&#26102;&#65292;&#22914;&#26524;&#27809;&#26377;&#36820;&#22238;&#20219;&#20309;&#20540;&#12290;&#35753;&#25105;&#20204;&#27604;&#36739;&#19968;&#19979;&#65306;<\/p>\n<pre><code>function returnNothing() {}\nvar_dump(returnNothing()); \/\/ Implicitly returns NULL\nfunction returnNull() { return NULL; }\nvar_dump(returnNull()); \/\/ Explicitly returns NULL\n<\/code><\/pre>\n<p>&#20351;&#29992;<code>NULL<\/code>&#40664;&#35748;&#21442;&#25968;&#20540;&#20063;&#26159;&#20540;&#24471;&#25552;&#20513;&#30340;&#12290;<\/p>\n<pre><code>function say($word = NULL) {\n    if(is_null($word)) {\n        echo 'No word to say.';\n    } else {\n        echo $word;\n    }\n}\nsay(); \/\/ Echoes 'No word to say.'\nsay('PHP!'); \/\/ Echoes 'PHP!'\n<\/code><\/pre>\n<h2>&#31354;&#20540;&#21512;&#24182;&#36816;&#31639;&#31526;<\/h2>\n<p>&#22312;PHP 7&#20013;&#24341;&#20837;&#30340;null coalescing&#36816;&#31639;&#31526;&#25552;&#20379;&#20102;&#19968;&#31181;&#20351;&#29992;&#40664;&#35748;&#20540;&#22788;&#29702;&#26102;&#30340;&#19968;&#31181;&#31616;&#27905;&#26041;&#27861;&#12290;<code>NULL<\/code>&#23427;&#30001;&#8230;<code>??<\/code>&#65306;<\/p>\n<pre><code>$username = $_GET['user'] ?? 'guest';\necho $username; \/\/ Outputs 'guest' if $_GET['user'] is not set\n<\/code><\/pre>\n<p>&#35813;&#25805;&#20316;&#31526;&#20063;&#21487;&#20197;&#38142;&#36215;&#26469;&#36827;&#34892;&#22810;&#20010;&#26816;&#26597;&#65306;<\/p>\n<pre><code>$username = $_POST['user'] ?? $_GET['user'] ?? 'guest';\necho $username;\n<\/code><\/pre>\n<h2>&#20351;&#29992;&#26143;&#33328;&#36816;&#31639;&#31526;&#22788;&#29702;NULL<\/h2>\n<p>PHP 7&#24341;&#20837;&#20102;&#31661;&#22836;&#36816;&#31639;&#31526;&#12290;<code>&lt;&gt;<\/code>&#21738;&#27454;&#36719;&#20214;&#20063;&#33021;&#22788;&#29702;<code>NULL<\/code>&#27604;&#36739;&#25805;&#20316;&#36820;&#22238;0&#22914;&#26524;&#20004;&#36793;&#30456;&#31561;&#65292;1&#22914;&#26524;&#24038;&#36793;&#22823;&#20110;&#21491;&#36793;&#65292;-1&#22914;&#26524;&#21491;&#36793;&#22823;&#20110;&#24038;&#36793;&#65306;<\/p>\n<pre><code>$a = NULL;\n$b = 0;\necho $a &lt;=&gt; $b; \/\/ Outputs -1\n<\/code><\/pre>\n<p>&#27492;&#22788;&#30340;&#32467;&#26524;&#34920;&#26126;&#65292;&#20174;&#35746;&#36141;&#26041;&#38754;&#26469;&#30475;&#65292;<code>NULL<\/code>&#34987;&#35748;&#20026;&#23567;&#20110;0&#12290;<\/p>\n<h2>&#22788;&#29702;&#25968;&#25454;&#24211;<\/h2>\n<p>&#22312;SQL&#25968;&#25454;&#24211;&#20013;&#65292;<code>NULL<\/code>&#34920;&#31034;&#32570;&#22833;&#25110;&#19981;&#36866;&#29992;&#30340;&#20540;&#12290;&#20351;&#29992;&#26102;&#38750;&#24120;&#37325;&#35201;&#12290;<code>isset()<\/code>&#21151;&#33021;&#29992;&#20110;&#26816;&#26597;&#25968;&#25454;&#24211;&#26597;&#35810;&#26159;&#21542;&#36820;&#22238;&#32467;&#26524;&#12290;<code>NULL<\/code>&#25110;&#32773;&#19968;&#20010;&#23454;&#38469;&#30340;&#32467;&#26524;&#65306;<\/p>\n<pre><code>\/\/ Assume $db is a database connection and the query might return a NULL value\n$result = $db-&gt;query('SELECT ...');\nif(isset($result)) {\n    \/\/ Handle result\n} else {\n    \/\/ Handle NULL\n}\n<\/code><\/pre>\n<h2>&#26368;&#20339;&#23454;&#36341;&#21644;&#38519;&#38449;<\/h2>\n<p>&#21306;&#20998;&#38750;&#24120;&#37325;&#35201;&#12290;<code>NULL<\/code>&#24182;&#19988;&#19981;&#33021;&#20026;&#20551;&#12289;&#26410;&#23450;&#20041;&#25110;&#31354;&#23383;&#31526;&#20018;&#12290;&#20351;&#29992;&#31867;&#22411;&#29305;&#23450;&#30340;&#26816;&#26597;&#65292;&#20363;&#22914;<code>is_null()<\/code>for the triple equals operator<code>===<\/code>&#19968;&#33324;&#26469;&#35828;&#65292;&#36825;&#31181;&#27604;&#36739;&#26356;&#20026;&#21487;&#38752;&#12290;<\/p>\n<p>&#27492;&#22806;&#65292;&#32771;&#34385;&#19968;&#19979;<code>NULL<\/code>&#35821;&#20041;&#20215;&#20540;&#26368;&#22823;&#30340;&#20540;&#24212;&#35813;&#34987;&#20351;&#29992;&#12290;&#26377;&#26102;&#65292;&#40664;&#35748;&#20540;&#25110;&#29978;&#33267;&#31354;&#23545;&#35937;&#21487;&#33021;&#26356;&#28165;&#26224;&#22320;&#20256;&#36798;&#24847;&#22270;&#12290;&#22987;&#32456;&#23545;&#29992;&#25143;&#36755;&#20837;&#36827;&#34892;&#26657;&#39564;&#21644;&#39564;&#35777;&#65292;&#22240;&#20026;&#20381;&#36182;&#20110;&#40664;&#35748;&#20540;&#21487;&#33021;&#20250;&#24102;&#26469;&#23433;&#20840;&#39118;&#38505;&#12290;<code>NULL<\/code>&#34920;&#31034;&#25968;&#25454;&#30340;&#32570;&#22833;&#21487;&#33021;&#20250;&#24341;&#20837;&#23433;&#20840;&#28431;&#27934;&#25110;&#38169;&#35823;&#12290;<\/p>\n<h2>&#32467;&#35770;<\/h2>\n<p>&#36825;&#31687;&#25945;&#31243;&#25552;&#20379;&#20102;&#20851;&#20110;&#30340;&#35814;&#23613;&#25351;&#21335;&#12290;<code>NULL<\/code>&#22312;PHP&#20013;&#12290;&#20174;&#31616;&#21333;&#30340;&#21464;&#37327;&#21021;&#22987;&#21270;&#21040;&#19982;null&#21512;&#24182;&#21644;&#26143;&#21495;&#36816;&#31639;&#31526;&#30456;&#20851;&#30340;&#39640;&#32423;&#20351;&#29992;&#65292;&#29702;&#35299;&#36825;&#20123;&#30693;&#35782;&#23545;&#20110;&#32534;&#31243;&#26469;&#35828;&#26159;&#38750;&#24120;&#37325;&#35201;&#30340;&#12290;<code>NULL<\/code>&#20801;&#35768;&#24744;&#32534;&#20889;&#26356;&#31616;&#27905;&#21644;&#20581;&#22766;&#30340;PHP&#20195;&#30721;&#12290;&#25317;&#25265;<code>NULL<\/code>&#20294;&#26159;&#65292;&#35831;&#21153;&#24517;&#35880;&#24910;&#21644;&#19968;&#33268;&#22320;&#20351;&#29992;&#23427;&#65292;&#20197;&#36991;&#20813;&#24847;&#22806;&#21518;&#26524;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#20171;&#32461; &#22312;PHP&#20013;&#65292;NULL&#36825;&#26159;&#19968;&#20010;&#29305;&#27530;&#30340;&#25968;&#25454;&#31867;&#22411;&#65292;&#34920;&#31034;..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-419","my1js","type-my1js","status-publish","hentry","my1js2nav-jcyy"],"acf":{"qian_art_seotitle":"","qian_art_seotitle_source":{"label":"SEO\u6807\u9898","type":"text","formatted_value":""},"qian_art_seokws":"","qian_art_seokws_source":{"label":"SEO\u5173\u952e\u8bcd","type":"text","formatted_value":""},"qian_art_stzhong":"","qian_art_stzhong_source":{"label":"\u4e2d | \u77ed\u6807\u9898","type":"text","formatted_value":""}},"_links":{"self":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js\/419","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js"}],"about":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/types\/my1js"}],"author":[{"embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/users\/1"}],"wp:attachment":[{"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/media?parent=419"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=419"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=419"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=419"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}