{"id":412,"date":"2025-06-10T20:04:37","date_gmt":"2025-06-10T12:04:37","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/412.html"},"modified":"2025-06-10T20:04:37","modified_gmt":"2025-06-10T12:04:37","slug":"php%e4%b8%ad%e7%9a%84%e5%b8%83%e5%b0%94%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/412.html","title":{"rendered":"PHP\u4e2d\u7684\u5e03\u5c14\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"<p><body><\/p>\n<h2>&#20171;&#32461;<\/h2>\n<p>&#22312;PHP&#20013;&#65292;&#24067;&#23572;&#25968;&#25454;&#31867;&#22411;&#34920;&#31034;&#20004;&#31181;&#21487;&#33021;&#30340;&#29366;&#24577;&#65306;true &#25110; false&#12290;&#23427;&#26159;&#29992;&#20110;&#25511;&#21046;&#32467;&#26500;&#65288;&#22914;if&#35821;&#21477;&#21644;&#24490;&#29615;&#65289;&#20197;&#21450;&#34920;&#36798;PHP&#24212;&#29992;&#31243;&#24207;&#20013;&#30340;&#26465;&#20214;&#36923;&#36753;&#30340;&#20851;&#38190;&#27010;&#24565;&#12290;<\/p>\n<h2>&#22312;PHP&#20013;&#29702;&#35299;&#24067;&#23572;&#31867;&#22411;&#26159;&#38750;&#24120;&#37325;&#35201;&#30340;&#65292;&#36825;&#28041;&#21450;&#21040;&#22522;&#26412;&#30340;&#36923;&#36753;&#21644;&#26465;&#20214;&#21028;&#26029;&#12290;&#20197;&#19979;&#26159;&#19968;&#20123;&#20851;&#20110;&#24067;&#23572;&#31867;&#22411;&#30340;&#35201;&#28857;&#65306;<\/p>\n<p>&#24067;&#23572;&#20540;&#26377;&#19977;&#31181;&#21487;&#33021;&#65306;true, false &#21644; null&#12290;<\/p>\n<p>&#20219;&#20309;&#38750;&#38646;&#25968;&#23383;&#12289;&#23383;&#31526;&#20018;&#25110;&#25968;&#32452;&#37117;&#35270;&#20026; true&#12290;<\/p>\n<p>&#38646;&#65288;0&#65289;&#12289;&#31354;&#23383;&#31526;&#20018;(&#8220;&#8221;)&#12289;&#31354;&#25968;&#32452;() &#25110; FALSE &#37117;&#34987;&#35270;&#20026; false&#12290;<\/p>\n<p>NULL &#26159;&#19968;&#20010;&#29305;&#27530;&#30340;&#20540;&#65292;&#34920;&#31034;&#27809;&#26377;&#25968;&#25454;&#25110;&#23545;&#35937;&#19981;&#23384;&#22312;&#12290;<\/p>\n<p>&#20351;&#29992; isset() &#20989;&#25968;&#21487;&#20197;&#26816;&#26597;&#21464;&#37327;&#26159;&#21542;&#24050;&#23450;&#20041;&#19988;&#19981;&#20026; null&#12290;<\/p>\n<p>&#20351;&#29992; empty() &#20989;&#25968;&#21487;&#20197;&#26816;&#26597;&#21464;&#37327;&#26159;&#21542;&#20026;&#31354;&#12290;<\/p>\n<p>&#21487;&#20197;&#20351;&#29992;&#19977;&#20803;&#36816;&#31639;&#31526;&#26469;&#31616;&#21270;&#26465;&#20214;&#34920;&#36798;&#24335;&#65306;<br \/>\n$result = ($condition) ? &#8216;yes&#8217; : &#8216;no&#8217;;<\/p>\n<p>&#22312;&#27604;&#36739;&#25805;&#20316;&#26102;&#65292;&#24067;&#23572;&#20540;&#24517;&#39035;&#36716;&#25442;&#20026;&#25972;&#25968;&#12290;true &#34987;&#36716;&#25442;&#20026; 1&#65292;false &#34987;&#36716;&#25442;&#20026; 0&#12290;<\/p>\n<p>&#22914;&#26524;&#38656;&#35201;&#27604;&#36739;&#20004;&#20010;&#24067;&#23572;&#20540;&#65292;&#21487;&#20197;&#30452;&#25509;&#36827;&#34892;&#27604;&#36739;&#65306;<br \/>\nif (true === false) {<br \/>\n \/\/ &#36825;&#27573;&#20195;&#30721;&#27704;&#36828;&#19981;&#20250;&#25191;&#34892;<br \/>\n}<\/p>\n<p>&#27880;&#24847;&#65292;&#24067;&#23572;&#24120;&#37327;&#19981;&#33021;&#29992;&#20110;&#38500;&#36171;&#20540;&#22806;&#30340;&#25805;&#20316;&#65292;&#20363;&#22914; if &#35821;&#21477;&#20013;&#30340;&#26465;&#20214;&#37096;&#20998;&#12290;<\/p>\n<p>&#36890;&#36807;&#29702;&#35299;&#21644;&#25484;&#25569;&#36825;&#20123;&#35268;&#21017;&#65292;&#20320;&#21487;&#20197;&#26356;&#26377;&#25928;&#22320;&#22788;&#29702; PHP &#20013;&#30340;&#24067;&#23572;&#31867;&#22411;&#21644;&#36923;&#36753;&#21028;&#26029;&#12290;<\/h2>\n<p>&#22312;PHP&#20013;&#65292;&#24067;&#23572;&#25968;&#25454;&#31867;&#22411;&#36890;&#24120;&#30001;&#27604;&#36739;&#25110;&#26465;&#20214;&#30340;&#32467;&#26524;&#36820;&#22238;&#12290;&#24403;&#35780;&#20272;&#20219;&#20309;&#26465;&#20214;&#26102;&#65292;&#37117;&#20250;&#36820;&#22238;&#30495;&#20540;&#25110;&#20551;&#20540;&#12290;&#35753;&#25105;&#20204;&#20808;&#30475;&#30475;&#22914;&#20309;&#23450;&#20041;&#24067;&#23572;&#21464;&#37327;&#65292;&#20351;&#29992;&#31616;&#21333;&#30340;true&#21644;false&#36171;&#20540;&#30340;&#26041;&#27861;&#12290;<\/p>\n<pre><code>\n$flag1 = true;\n$flag2 = false;\n<\/code><\/pre>\n<p>PHP &#26159;&#19968;&#31181;&#26494;&#25955;&#31867;&#22411;&#30340;&#35821;&#35328;&#65292;&#36825;&#24847;&#21619;&#30528;&#21464;&#37327;&#19981;&#38656;&#35201;&#22768;&#26126;&#20854;&#25968;&#25454;&#31867;&#22411;&#12290;&#24067;&#23572;&#20540;&#20063;&#21487;&#20197;&#20316;&#20026;&#34920;&#36798;&#24335;&#30340;&#32467;&#26524;&#65306;<\/p>\n<pre><code>\n$isValid = (3 &gt; 2); \/\/ true\n$isIdentical = (3 === '3'); \/\/ false\n<\/code><\/pre>\n<h2>&#24067;&#23572;&#36816;&#31639;<\/h2>\n<p>&#20320;&#21487;&#20197;&#20351;&#29992;&#36923;&#36753;&#36816;&#31639;&#31526;&#23545;&#24067;&#23572;&#20540;&#36827;&#34892;&#36923;&#36753;&#25805;&#20316;&#12290;&#22522;&#26412;&#30340;&#36923;&#36753;&#36816;&#31639;&#31526;&#21253;&#25324;<code>&amp;&amp;<\/code>(AND)<code>||<\/code>OK, and<code>!<\/code>(&#26080;)<\/p>\n<pre><code>\n$user_is_admin = true;\n$user_is_logged_in = true;\n$can_access_dashboard = $user_is_admin &amp;&amp; $user_is_logged_in;\n<\/code><\/pre>\n<p>&#23545;&#19981;&#36215;&#65292;&#24744;&#30340;&#38382;&#39064;&#19981;&#23436;&#25972;&#65292;&#35831;&#24744;&#37325;&#26032;&#25551;&#36848;&#19968;&#19979;&#12290;<code>$can_access_dashboard<\/code>&#21464;&#37327;&#21482;&#26377;&#22312;&#20004;&#20010;&#26465;&#20214;&#37117;&#20026;&#30495;&#26102;&#25165;&#20250;&#20026;&#30495;&#12290;<code>$user_is_admin<\/code>and&#20063;&#26159;&#65292;&#25105;&#20204;&#22312;&#31561;&#20320;&#12290;<code>$user_is_logged_in<\/code>&#30830;&#23454;&#26159;&#36825;&#26679;&#12290;&#21516;&#26679;&#65292;&#20320;&#21487;&#20197;&#20351;&#29992;<code>||<\/code>&#23545;&#20110;&#19968;&#20010;&#25110;&#25805;&#20316;&#12290;<code>!<\/code>&#21542;&#23450;&#19968;&#20010;&#24067;&#23572;&#20540;&#12290;<\/p>\n<h2>&#31867;&#22411;&#36716;&#25442;&#21644;&#24067;&#23572;&#20540;<\/h2>\n<p>&#22312;PHP&#20013;&#65292;&#21487;&#20197;&#20351;&#29992;(bool)&#25110;(boolean)&#26469;&#23558;&#21464;&#37327;&#36716;&#25442;&#20026;&#24067;&#23572;&#19978;&#19979;&#25991;&#12290;&#38750;&#24067;&#23572;&#20540;&#34987;&#35270;&#20026;&#30495;&#65292;&#38500;&#20102;&#20960;&#20010;&ldquo;&#20551;&#20540;&rdquo;&#12290;&#36825;&#20123;&#21253;&#25324;&#25972;&#25968;0&#21644;-0&#12289;&#28014;&#28857;&#25968;0.0&#21644;-0.0&#12289;&#31354;&#23383;&#31526;&#20018;&#21644;&#23383;&#31526;&#20018;&ldquo;0&rdquo;&#12289;&#21253;&#21547;&#38646;&#20803;&#32032;&#30340;&#25968;&#32452;&#12289;&#29305;&#27530;&#31867;&#22411;NULL&#20197;&#21450;&#20174;&#31354;&#26631;&#31614;&#21019;&#24314;&#30340;SimpleXML&#23545;&#35937;&#12290;<\/p>\n<pre><code>\n$is_empty_string = (boolean) ''; \/\/ false\n$is_zero = (boolean) 0; \/\/ false\n$is_array_empty = (boolean) []; \/\/ false\n<\/code><\/pre>\n<h2>&#19982;&#24067;&#23572;&#31867;&#22411;&#36827;&#34892;&#27604;&#36739;<\/h2>\n<p>&#22312;&#27604;&#36739;&#21464;&#37327;&#21644;&#24067;&#23572;&#20540;&#26102;&#65292;&#38656;&#35201;&#27880;&#24847;PHP&#30340;&#31867;&#22411;&#36716;&#25442;&#38382;&#39064;&#12290;&#20351;&#29992;&#26494;&#25955;&#27604;&#36739;&#65288;==&#65289;&#21487;&#33021;&#20250;&#23548;&#33268;&#24847;&#22806;&#30340;&#32467;&#26524;&#65292;&#22240;&#20026;&#21482;&#26377;&#22312;&#31867;&#22411;&#36716;&#25442;&#21518;&#25165;&#36827;&#34892;&#27604;&#36739;&#12290;&#36890;&#24120;&#25512;&#33616;&#20351;&#29992;&#20005;&#26684;&#27604;&#36739;&#65288;===&#65289;&#65292;&#20197;&#30830;&#20445;&#20540;&#21644;&#31867;&#22411;&#37117;&#21305;&#37197;&#12290;<\/p>\n<pre><code>\nis_bool('php') == true; \/\/ true, as 'php' is a truthy value\n'php' === true; \/\/ false, because 'php' is not a boolean type\n<\/code><\/pre>\n<h2>&#24067;&#23572;&#20540;&#22312;&#25511;&#21046;&#32467;&#26500;&#20013;<\/h2>\n<p>&#22312;PHP&#20013;&#65292;&#25511;&#21046;&#32467;&#26500;&#22823;&#37327;&#20351;&#29992;&#24067;&#23572;&#31867;&#22411;&#12290;&#20197;&#19979;&#26159;&#22312;if&#35821;&#21477;&#12289;switch&#35821;&#21477;&#21644;while&#24490;&#29615;&#20013;&#30340;&#31034;&#20363;&#65306;<\/p>\n<pre><code>\nif ($is_logged_in) {\n    \/\/ code to execute if user is logged in\n}\n\nswitch ($is_logged_in) {\n    case true:\n        \/\/ code if true\n        break;\n\n    case false:\n        \/\/ code if false\n        break;\n}\n\nwhile ($keep_running) {\n    \/\/ code to execute as long as $keep_running is true\n}\n<\/code><\/pre>\n<h2>&#30495;&#29702;&#20540;&#22312;&#26465;&#20214;&#20013;<\/h2>\n<p>&#22312;&#20351;&#29992;PHP&#20013;&#30340;&#24067;&#23572;&#20540;&#65288;truthy&#21644;falsy&#20540;&#65289;&#26102;&#35201;&#23567;&#24515;&#65292;&#22312;&#26465;&#20214;&#35821;&#21477;&#20013;&#20351;&#29992;&#23427;&#20204;&#12290;&#20363;&#22914;&#65292;&#31354;&#25968;&#32452;&#25110;null&#21464;&#37327;&#20250;&#35780;&#20272;&#20026;false&#12290;<\/p>\n<pre><code>\n$maybeEmpty = [];\nif ($maybeEmpty) {\n    \/\/ This block will not execute\n}\n\n$possiblyNull = null;\nif ($possiblyNull) {\n    \/\/ Neither will this block\n}\n<\/code><\/pre>\n<h2>&#39640;&#32423;&#24067;&#23572;&#27010;&#24565;<\/h2>\n<p>&#21487;&#20197;&#36935;&#21040;&#39640;&#32423;&#22330;&#26223;&#65292;&#20854;&#20013;&#24067;&#23572;&#20540;&#21464;&#24471;&#33267;&#20851;&#37325;&#35201;&#12290;&#20854;&#20013;&#19968;&#20010;&#20363;&#23376;&#26159;&#20351;&#29992;&#20301;&#36816;&#31639;&#31526;&#26469;&#25805;&#32437;&#25972;&#25968;&#20013;&#30340;&#29305;&#23450;&#20301;&#12290;&#23613;&#31649;&#36825;&#36229;&#20986;&#20102;&#31616;&#21333;&#30340;&#30495;&#25110;&#20551;&#36923;&#36753;&#30340;&#33539;&#30068;&#65292;&#20294;&#24067;&#23572;&#20195;&#25968;&#30340;&#22522;&#26412;&#21407;&#29702;&#20173;&#28982;&#36866;&#29992;&#12290;<\/p>\n<pre><code>\n$user_permissions = 0b0011;\n$can_edit_posts  = 0b0001;\n\n\/\/ Check if user has 'edit posts' permission\n$has_permission = ($user_permissions &amp; $can_edit_posts) === $can_edit_posts;\n<\/code><\/pre>\n<h2>&#32467;&#35770;&#12290;<\/h2>\n<p>&#22312;PHP&#20013;&#65292;&#24067;&#23572;&#25968;&#25454;&#31867;&#22411;&#26082;&#31616;&#21333;&#21448;&#19981;&#21487;&#25110;&#32570;&#12290;&#29702;&#35299;true&#21644;false&#20540;&#26159;&#22914;&#20309;&#30830;&#23450;&#12289;&#25805;&#32437;&#21644;&#20351;&#29992;&#30340;&#65292;&#21487;&#20197;&#24110;&#21161;&#24744;&#32534;&#20889;&#26356;&#31283;&#20581;&#19988;&#21487;&#38752;&#30340;&#20195;&#30721;&#12290;&#22987;&#32456;&#32771;&#34385;&#24744;&#20351;&#29992;&#24067;&#23572;&#20540;&#30340;&#19978;&#19979;&#25991;&#65292;&#36991;&#20813;&#31867;&#22411;&#28151;&#28102;&#30340;&#24120;&#35265;&#38519;&#38449;&#65292;&#24182;&#20248;&#20808;&#36873;&#25321;&#20005;&#26684;&#30340;&#27604;&#36739;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#20171;&#32461; &#22312;PHP&#20013;&#65292;&#24067;&#23572;&#25968;&#25454;&#31867;&#22411;&#34920;&#31034;&#20004;&#31181;&#21487;&#33021;&#30340;&#29366;&#038;#24..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-412","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\/412","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=412"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=412"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=412"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}