{"id":482,"date":"2025-06-10T21:06:30","date_gmt":"2025-06-10T13:06:30","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/482.html"},"modified":"2025-06-10T21:06:30","modified_gmt":"2025-06-10T13:06:30","slug":"%e7%90%86%e8%a7%a3php%e4%b8%ad%e7%9a%84%e6%b7%b7%e5%90%88%e7%b1%bb%e5%9e%8b%ef%bc%885%e4%b8%aa%e7%a4%ba%e4%be%8b%ef%bc%89","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/482.html","title":{"rendered":"\u7406\u89e3PHP\u4e2d\u7684\u6df7\u5408\u7c7b\u578b\uff085\u4e2a\u793a\u4f8b\uff09"},"content":{"rendered":"<p><body><\/p>\n<h2>&#27010;&#36848;<\/h2>\n<p>&#27426;&#36814;&#21442;&#21152;&#26412;&#25351;&#21335;&#65292;&#26088;&#22312;&#24110;&#21161;&#24744;&#29702;&#35299;PHP&#20013;&#30340;&#28151;&#21512;&#31867;&#22411;&#12290;&#20316;&#20026;&#21160;&#24577;&#31867;&#22411;&#30340;&#35821;&#35328;&#65292;PHP&#25552;&#20379;&#20102;&#28789;&#27963;&#24615;&#65292;&#26377;&#26102;&#20250;&#23548;&#33268;&#28151;&#28102;&#65292;&#29305;&#21035;&#26159;&#22312;&#22788;&#29702;&#28151;&#21512;&#31867;&#22411;&#26102;&#12290;&#22312;&#26412;&#25945;&#31243;&#20013;&#65292;&#25105;&#20204;&#23558;&#25506;&#35752;&#20160;&#20040;&#26159;&#28151;&#21512;&#31867;&#22411;&#12289;&#23427;&#20204;&#30340;&#21547;&#20041;&#20197;&#21450;&#22914;&#20309;&#36890;&#36807;&#20116;&#20010;&#35814;&#32454;&#31034;&#20363;&#65288;&#20174;&#22522;&#30784;&#21040;&#39640;&#32423;&#27010;&#24565;&#65289;&#26377;&#25928;&#22320;&#31649;&#29702;&#23427;&#20204;&#12290;&#26080;&#35770;&#24744;&#26159;&#21021;&#23398;&#32773;&#36824;&#26159;&#32463;&#39564;&#20016;&#23500;&#30340;PHP&#24320;&#21457;&#20154;&#21592;&#65292;&#20102;&#35299;&#28151;&#21512;&#31867;&#22411;&#23545;&#20110;&#32534;&#20889;&#20855;&#26377;&#24378;&#22823;&#21151;&#33021;&#12289;&#39640;&#25928;&#19988;&#26080;&#38169;&#35823;&#20195;&#30721;&#30340;&#20195;&#30721;&#33267;&#20851;&#37325;&#35201;&#12290;<\/p>\n<h2>&#22312;PHP&#20013;&#65292;&#28151;&#21512;&#31867;&#22411;&#65288;Mixed&#65289;&#26159;&#19968;&#31181;&#25968;&#25454;&#31867;&#22411;&#65292;&#23427;&#20801;&#35768;&#21464;&#37327;&#21253;&#21547;&#20219;&#20309;&#31867;&#22411;&#30340;&#20540;&#65292;&#21253;&#25324;&#22522;&#26412;&#31867;&#22411;&#21644;&#24341;&#29992;&#31867;&#22411;&#12290;&#20363;&#22914;&#65306;<br \/>\n$a = 5; \/\/ &#25972;&#25968;<br \/>\n$b = &#8220;hello&#8221;; \/\/ &#23383;&#31526;&#20018;<br \/>\n$c = true; \/\/ &#24067;&#23572;&#20540;<br \/>\n$d = null; \/\/ &#31354;&#20540;<\/p>\n<p>echo $a + $b; \/\/ &#36755;&#20986;: hello5<br \/>\n&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;$a &#26159;&#25972;&#25968;&#65292;$b &#26159;&#23383;&#31526;&#20018;&#65292;&#23427;&#20204;&#34987;&#31616;&#21333;&#22320;&#30456;&#21152;&#20102;&#12290;&#38656;&#35201;&#27880;&#24847;&#30340;&#26159;&#65292;&#36825;&#31181;&#25805;&#20316;&#20250;&#33258;&#21160;&#36716;&#25442;&#20026;&#23383;&#31526;&#20018;&#30340;&#25340;&#25509;&#65292;&#32780;&#19981;&#26159;&#25191;&#34892;&#31639;&#26415;&#36816;&#31639;&#12290;<br \/>\necho $c * $d; \/\/ &#36755;&#20986;: false<br \/>\n&#36825;&#37324;&#65292;$c &#21644; $d &#37117;&#26159;&#24067;&#23572;&#20540;&#65292;&#25152;&#20197;&#23427;&#20204;&#34987;&#36923;&#36753;&#22320;&#20056;&#22312;&#19968;&#36215;&#65292;&#36820;&#22238; false&#12290;<br \/>\n&#36825;&#31181;&#28789;&#27963;&#24615;&#20351;&#24471;&#28151;&#21512;&#31867;&#22411;&#38750;&#24120;&#36866;&#21512;&#22788;&#29702;&#26469;&#33258;&#19981;&#21516;&#26469;&#28304;&#30340;&#25968;&#25454;&#65292;&#20294;&#21516;&#26102;&#20063;&#22686;&#21152;&#20102;&#20195;&#30721;&#30340;&#22797;&#26434;&#24615;&#65292;&#38656;&#35201;&#26356;&#22810;&#30340;&#26816;&#26597;&#26469;&#30830;&#20445;&#25152;&#26377;&#21464;&#37327;&#37117;&#24050;&#27491;&#30830;&#21021;&#22987;&#21270;&#24182;&#19988;&#36866;&#21512;&#36827;&#34892;&#21508;&#31181;&#25805;&#20316;&#12290;<\/h2>\n<p>&#22312;PHP&#20013;&#65292;&#21464;&#37327;&#26080;&#38656;&#26174;&#24335;&#22768;&#26126;&#21363;&#21487;&#20351;&#29992;&#12290;&#36825;&#24847;&#21619;&#30528;&#21464;&#37327;&#30340;&#31867;&#22411;&#30001;&#20854;&#20351;&#29992;&#30340;&#19978;&#19979;&#25991;&#20915;&#23450;&#12290;&#28151;&#21512;&#31867;&#22411;&#26159;&#19968;&#31181;&#26415;&#35821;&#65292;&#29992;&#20110;&#25551;&#36848;&#21487;&#20197;&#22312;&#33050;&#26412;&#25191;&#34892;&#36807;&#31243;&#20013;&#23384;&#20648;&#19981;&#21516;&#31867;&#22411;&#20540;&#65288;&#22914;&#25972;&#25968;&#12289;&#23383;&#31526;&#20018;&#21644;&#23545;&#35937;&#65289;&#30340;&#21464;&#37327;&#12290;&#27492;&#21151;&#33021;&#25552;&#20379;&#20102;&#28789;&#27963;&#24615;&#65292;&#20294;&#38656;&#35201;&#35880;&#24910;&#22788;&#29702;&#20197;&#36991;&#20813;&#24847;&#22806;&#34892;&#20026;&#12290;<\/p>\n<h2>&#31034;&#20363; 1&#65306;&#22522;&#26412;&#28151;&#21512;&#31867;&#22411;&#29992;&#27861;<\/h2>\n<p>&#35753;&#25105;&#20204;&#36890;&#36807;&#19968;&#20010;&#22522;&#26412;&#30340;&#20363;&#23376;&#26469;&#35828;&#26126;&#22312;PHP&#20013;&#21464;&#37327;&#31867;&#22411;&#22914;&#20309;&#21487;&#20197;&#25913;&#21464;&#65306;<\/p>\n<pre><code>&lt;?php\n$value = 42; \/\/ Integer\necho gettype($value); \/\/ Output: integer\n$value = \"A string value\"; \/\/ String\necho \"n\" . gettype($value); \/\/ Output: string\n?&gt;<\/code><\/pre>\n<p>&#36825;&#20010;&#31034;&#20363;&#23637;&#31034;&#20102;PHP&#21464;&#37327;&#30340;&#21160;&#24577;&#24615;&#36136;&#12290;&#26368;&#21021;&#65292;$x &#30340;&#20540;&#20026; 100&#12290;<code>$value<\/code>&#21464;&#37327;&#35774;&#32622;&#20026;&#25972;&#25968;&#12290;&#28982;&#32780;&#65292;&#25105;&#20204;&#21487;&#20197;&#36890;&#36807;&#23558;&#20854;&#20540;&#36171;&#32473;&#19968;&#20010;&#23383;&#31526;&#20018;&#20540;&#26469;&#36731;&#26494;&#22320;&#23558;&#20854;&#31867;&#22411;&#26356;&#25913;&#20026;&#23383;&#31526;&#20018;&#12290;<code>gettype()<\/code>&#20989;&#25968;&#29992;&#20110;&#22312;&#27599;&#27425;&#38454;&#27573;&#25171;&#21360;&#21464;&#37327;&#30340;&#31867;&#22411;&#12290;<\/p>\n<h2>&#31034;&#20363; 2&#65306;&#20989;&#25968;&#22788;&#29702;&#28151;&#21512;&#31867;&#22411;<\/h2>\n<p>&#25509;&#19979;&#26469;&#65292;&#25105;&#20204;&#23558;&#30475;&#21040;&#20989;&#25968;&#22914;&#20309;&#22788;&#29702;&#21442;&#25968;&#21644;&#36820;&#22238;&#20540;&#30340;&#28151;&#21512;&#31867;&#22411;&#12290;&#36825;&#23545;&#20110;&#35774;&#35745;&#29992;&#20110;&#22788;&#29702;&#22810;&#31181;&#25968;&#25454;&#31867;&#22411;&#30340;&#20989;&#25968;&#23588;&#20854;&#26377;&#29992;&#12290;<\/p>\n<pre><code>&lt;?php\nfunction printValue($value) {\n    if (is_int($value)) {\n        echo \"The value is an integer: \" . $value . \"n\";\n    } elseif (is_string($value)) {\n        echo \"The value is a string: '\" . $value . \"'n\";\n    }\n}\nprintValue(10);\nprintValue('Hello');\n?&gt;<\/code><\/pre>\n<p>&#22312;&#36825;&#19968;&#20363;&#23376;&#37324;&#65292;<code>printValue<\/code>&#20989;&#25968;&#20351;&#29992;&#36755;&#20837;&#21442;&#25968;&#31867;&#22411;&#26816;&#26597;&#21151;&#33021;&#12290;<code>is_int()<\/code>and &#26159;&ldquo;&#21644;&rdquo;&#30340;&#24847;&#24605;&#65292;&#36890;&#24120;&#29992;&#20110;&#36830;&#25509;&#20004;&#20010;&#35789;&#25110;&#30701;&#35821;&#12290;<code>is_string()<\/code>&#22312;&#20915;&#23450;&#25171;&#21360;&#20043;&#21069;&#65292;&#20808;&#26816;&#26597;&#19968;&#19979;&#21151;&#33021;&#26159;&#21542;&#33021;&#27491;&#30830;&#22788;&#29702;&#21508;&#31181;&#36755;&#20837;&#31867;&#22411;&#12290;&#36825;&#26159;&#19968;&#31181;&#30830;&#20445;&#20989;&#25968;&#21487;&#20197;&#27491;&#30830;&#22788;&#29702;&#22810;&#31181;&#36755;&#20837;&#31867;&#22411;&#30340;&#31616;&#21333;&#26041;&#27861;&#12290;<\/p>\n<h2>&#31034;&#20363; 3&#65306;&#20026;&#26356;&#22909;&#30340;&#21487;&#38752;&#24615;&#32534;&#20889;&#31867;&#22411;&#22768;&#26126;<\/h2>\n<p>&#38543;&#30528;PHP&#30340;&#19981;&#26029;&#21457;&#23637;&#65292;&#23427;&#24050;&#32463;&#24341;&#20837;&#20102;&#20989;&#25968;&#21442;&#25968;&#12289;&#36820;&#22238;&#31867;&#22411;&#21644;&#23646;&#24615;&#30340;&#31867;&#22411;&#22768;&#26126;&#65292;&#36825;&#25552;&#39640;&#20102;&#20195;&#30721;&#30340;&#21487;&#38752;&#24615;&#21644;&#21487;&#35835;&#24615;&#12290;&#35753;&#25105;&#20204;&#30475;&#30475;&#22914;&#20309;&#22768;&#26126;&#31867;&#22411;&#21487;&#20197;&#24110;&#21161;&#26356;&#26377;&#25928;&#22320;&#31649;&#29702;&#28151;&#21512;&#31867;&#22411;&#30340;&#20195;&#30721;&#12290;<\/p>\n<pre><code>&lt;?php\nfunction sum(int $a, int $b): int {\n    return $a + $b;\n}\ntry {\n    echo sum(5, \"3\"); \/\/ Output: 8\n} catch (TypeError $e) {\n    echo 'Error: ' . $e-&gt;getMessage();\n}\n?&gt;<\/code><\/pre>\n<p>&#36825;&#20010;&#20363;&#23376;&#23637;&#31034;&#20102;&#31867;&#22411;&#22768;&#26126;&#22312;&#20989;&#25968;&#21442;&#25968;&#21644;&#36820;&#22238;&#31867;&#22411;&#20013;&#30340;&#20351;&#29992;&#12290;&#36890;&#36807;&#23558;&#20004;&#20010;&#21442;&#25968;&#37117;&#22768;&#26126;&#20026;&#25972;&#25968;&#65292;&#25105;&#20204;&#30830;&#20445;&#20256;&#36882;&#32473;&#20989;&#25968;&#30340;&#20219;&#20309;&#38750;&#25972;&#25968;&#20540;&#37117;&#20250;&#23548;&#33268;&#38169;&#35823;&#12290;<code>TypeError<\/code>&#22312;&#36825;&#37324;&#65292;PHP &#33258;&#21160;&#23558;&#23383;&#31526;&#20018; &#8220;3&#8221; &#36716;&#25442;&#20026;&#25972;&#25968;&#65292;&#20174;&#32780;&#25104;&#21151;&#25191;&#34892;&#20102;&#25805;&#20316;&#12290;<\/p>\n<h2>&#31034;&#20363; 4&#65306;&#28789;&#27963;&#19988;&#21487;&#38752;&#30340;&#65292;&#20351;&#29992;&#32852;&#21512;&#31867;&#22411;<\/h2>\n<p>PHP 8 &#24341;&#20837;&#20102;&#32852;&#21512;&#31867;&#22411;&#65292;&#20801;&#35768;&#24320;&#21457;&#32773;&#22768;&#26126;&#21442;&#25968;&#12289;&#36820;&#22238;&#31867;&#22411;&#21644;&#23646;&#24615;&#30340;&#32452;&#21512;&#31867;&#22411;&#12290;&#36825;&#19968;&#29305;&#24615;&#22312;&#22788;&#29702;&#28151;&#21512;&#31867;&#22411;&#26102;&#26082;&#25552;&#20379;&#20102;&#28789;&#27963;&#24615;&#20063;&#20445;&#35777;&#20102;&#21487;&#38752;&#24615;&#12290;<\/p>\n<pre><code>&lt;?php\nfunction concatenateOrAdd(string|int $a, string|int $b): string|int\n{\n    if (is_int($a) &amp;&amp; is_int($b)) {\n        return $a + $b;\n    } else {\n        return $a . $b;\n    }\n}\necho concatenateOrAdd(5, 10); \/\/ Output: 15\necho \"n\" . concatenateOrAdd('Hello', ' World'); \/\/ Output: 'Hello World'\n?&gt;<\/code><\/pre>\n<p>&#22312;&#36825;&#19968;&#31034;&#20363;&#20013;&#65292;&#20989;&#25968;<code>concatenateOrAdd<\/code>&#23427;&#21487;&#20197;&#25509;&#21463;&#23383;&#31526;&#20018;&#21644;&#25972;&#25968;&#20316;&#20026;&#21442;&#25968;&#65292;&#26681;&#25454;&#36755;&#20837;&#30340;&#31867;&#22411;&#36820;&#22238;&#30456;&#24212;&#30340;&#23383;&#31526;&#20018;&#25110;&#25972;&#25968;&#12290;&#36825;&#23637;&#31034;&#20102;&#22914;&#20309;&#20351;&#29992;&#32852;&#21512;&#31867;&#22411;&#20197;&#23433;&#20840;&#30340;&#26041;&#24335;&#22788;&#29702;&#28151;&#21512;&#31867;&#22411;&#30340;&#28789;&#27963;&#24615;&#12290;<\/p>\n<h2>&#31034;&#20363; 5&#65306;&#20351;&#29992;&#27867;&#22411;&#31867;&#22411;&#21644;&#31867;<\/h2>\n<p>&#34429;&#28982;PHP&#24182;&#19981;&#25903;&#25345;&#20687;&#20854;&#20182;&#35821;&#35328;&#19968;&#26679;&#25903;&#25345;&#36890;&#29992;&#31867;&#22411;&#65292;&#20294;&#25105;&#20204;&#21487;&#20197;&#36890;&#36807;&#31867;&#21644;&#25509;&#21475;&#26469;&#27169;&#25311;&#36825;&#31181;&#34892;&#20026;&#65292;&#22312;&#38754;&#21521;&#23545;&#35937;&#30340;&#26041;&#24335;&#19979;&#22788;&#29702;&#28151;&#21512;&#31867;&#22411;&#30340;&#20540;&#12290;<\/p>\n<pre><code>&lt;?php\nclass Container {\n    private mixed $value;\n    public function __construct(mixed $value) {\n        $this-&gt;value = $value;\n    }\n    public function getValue(): mixed {\n        return $this-&gt;value;\n    }\n}\n$intContainer = new Container(10);\n$stringContainer = new Container('Hello');\necho $intContainer-&gt;getValue(); \/\/ Output: 10\necho \"n\" . $stringContainer-&gt;getValue(); \/\/ Output: 'Hello'\n?&gt;<\/code><\/pre>\n<p>&#36825;&#20010;&#39640;&#32423;&#31034;&#20363;&#23637;&#31034;&#20102;&#25105;&#20204;&#22914;&#20309;&#22312;&#31867;&#20013;&#23553;&#35013;&#28151;&#21512;&#31867;&#22411;&#65292;&#21033;&#29992;&#36825;&#19968;&#28857;&#12290;<code>mixed<\/code>PHP 8 &#24341;&#20837;&#20102;&#31867;&#22411;&#25552;&#31034;&#65288;Type Hinting&#65289;&#12290;<code>Container<\/code>&#26500;&#36896;&#20989;&#25968;&#25509;&#21463;&#20219;&#20309;&#31867;&#22411;&#30340;&#20540;&#65292;&#24182;&#20351;&#29992;&#23427;&#36820;&#22238;&#12290;<code>getValue<\/code>&#26041;&#27861;&#12290;&#36825;&#31181;&#26041;&#27861;&#22312;&#20445;&#25345;&#38754;&#21521;&#23545;&#35937;&#35774;&#35745;&#30340;&#31867;&#22411;&#23433;&#20840;&#30340;&#21516;&#26102;&#25552;&#20379;&#20102;&#26356;&#22823;&#30340;&#28789;&#27963;&#24615;&#12290;<\/p>\n<h2>&#32467;&#35770;&#12290;<\/h2>\n<p>&#29702;&#35299;&#24182;&#26377;&#25928;&#22320;&#31649;&#29702;PHP&#20013;&#30340;&#28151;&#21512;&#31867;&#22411;&#23545;&#20110;&#21019;&#24314;&#28789;&#27963;&#12289;&#31283;&#20581;&#19988;&#39640;&#25928;&#30340;&#24212;&#29992;&#31243;&#24207;&#33267;&#20851;&#37325;&#35201;&#12290;&#36890;&#36807;&#20174;&#31616;&#21333;&#30340;&#31867;&#22411;&#26816;&#26597;&#24320;&#22987;&#65292;&#36880;&#27493;&#36827;&#21270;&#21040;&#31867;&#22411;&#22768;&#26126;&#12289;&#32852;&#21512;&#31867;&#22411;&#21644;&#38754;&#21521;&#23545;&#35937;&#35299;&#20915;&#26041;&#26696;&#65292;&#24320;&#21457;&#20154;&#21592;&#21487;&#20197;&#21033;&#29992;PHP&#31867;&#22411;&#31995;&#32479;&#30340;&#28508;&#21147;&#26469;&#32534;&#20889;&#26356;&#28165;&#26224;&#12289;&#26356;&#21487;&#38752;&#30340;&#20195;&#30721;&#12290;&#25317;&#25265;&#36825;&#20123;&#27010;&#24565;&#21644;&#25216;&#26415;&#65292;&#20197;&#25552;&#21319;&#24744;&#30340;PHP&#24320;&#21457;&#25216;&#33021;&#33267;&#26032;&#39640;&#24230;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#27010;&#36848; &#27426;&#36814;&#21442;&#21152;&#26412;&#25351;&#21335;&#65292;&#26088;&#22312;&#24110;&#21161;&#24744;&#29702;&#35299;PHP&#20013;&#30340;&#038;#28..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-482","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\/482","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=482"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=482"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=482"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}