{"id":443,"date":"2025-06-10T20:31:44","date_gmt":"2025-06-10T12:31:44","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/443.html"},"modified":"2025-06-10T20:31:44","modified_gmt":"2025-06-10T12:31:44","slug":"php%e7%ae%ad%e5%a4%b4%e5%87%bd%e6%95%b0%ef%bc%9a%e5%85%a8%e9%9d%a2%e6%8c%87%e5%8d%97","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/443.html","title":{"rendered":"PHP\u7bad\u5934\u51fd\u6570\uff1a\u5168\u9762\u6307\u5357"},"content":{"rendered":"<p><body><\/p>\n<h2>&#27010;&#35272;<\/h2>\n<p>&#31661;&#22836;&#20989;&#25968;&#65292;&#22312;PHP 7.4&#20013;&#24341;&#20837;&#65292;&#25552;&#20379;&#20102;&#19968;&#31181;&#26356;&#31616;&#27905;&#30340;&#35821;&#27861;&#26469;&#32534;&#20889;&#21311;&#21517;&#20989;&#25968;&#12290;&#26412;&#25351;&#21335;&#23558;&#20197;&#36880;&#27493;&#31034;&#20363;&#30340;&#24418;&#24335;&#20026;&#24744;&#25552;&#20379;&#20851;&#20110;PHP&#20013;&#30340;&#31661;&#22836;&#20989;&#25968;&#30340;&#20840;&#38754;&#29702;&#35299;&#12290;<\/p>\n<h2>&#31661;&#22836;&#20989;&#25968;&#30340;&#20171;&#32461;<\/h2>\n<p>&#22312;PHP&#29256;&#26412;7.4&#20013;&#39318;&#27425;&#24341;&#20837;&#20102;&#31661;&#22836;&#20989;&#25968;&#65292;&#36825;&#26159;&#19968;&#31181;&#29992;&#20110;&#21311;&#21517;&#20989;&#25968;&#30340;&#31616;&#27905;&#35821;&#27861;&#12290;&#23427;&#20204;&#20801;&#35768;&#20197;&#26356;&#31616;&#27905;&#30340;&#26041;&#24335;&#20256;&#36882;&#20989;&#25968;&#20316;&#20026;&#21442;&#25968;&#25110;&#22312;&#21508;&#31181;&#31243;&#24207;&#21270;&#22330;&#26223;&#20013;&#20351;&#29992;&#36825;&#20123;&#20989;&#25968;&#32780;&#26080;&#38656;&#36827;&#34892;&#20840;&#21151;&#33021;&#30340;&#21629;&#21517;&#20989;&#25968;&#22768;&#26126;&#12290;&#22312;PHP&#30340;&#20256;&#32479;&#21311;&#21517;&#20989;&#25968;&#20013;&#65292;&#23427;&#20204;&#36890;&#36807;&#20197;&#19979;&#26041;&#24335;&#22768;&#26126;&#65306;<code>function<\/code>&#20851;&#38190;&#23383;&#65292;&#26377;&#26102;&#20250;&#23548;&#33268;&#20989;&#25968;&#20307;&#30456;&#23545;&#31616;&#21333;&#30340;&#20195;&#30721;&#26174;&#24471;&#20887;&#38271;&#12290;<\/p>\n<p>&#36825;&#26159;&#19968;&#20010;PHP&#20013;&#30340;&#21311;&#21517;&#20989;&#25968;&#30340;&#31034;&#20363;&#65306;<\/p>\n<pre><code>\n$sum = function($a, $b) {\n    return $a + $b;\n};\n\necho $sum(2, 3); \/\/ Outputs: 5\n<\/code><\/pre>\n<p>&#20351;&#29992;&#31661;&#22836;&#20989;&#25968;&#65292;&#21487;&#20197;&#26356;&#31616;&#27905;&#22320;&#20889;&#20986;&#30456;&#21516;&#30340;&#25805;&#20316;&#65306;<\/p>\n<pre><code>\n$sum = fn($a, $b) =&gt; $a + $b;\n\necho $sum(2, 3); \/\/ Outputs: 5\n<\/code><\/pre>\n<h2>&#35821;&#27861;&#21644;&#29992;&#27861;<\/h2>\n<p>&#31661;&#22836;&#20989;&#25968;&#26377;&#31616;&#27905;&#30340;&#35821;&#27861;&#65306;function name (parameter) { body }&#65292;&#20854;&#20013; name &#26159;&#20989;&#25968;&#21517;&#31216;&#65288;&#21487;&#36873;&#65289;&#65292;parameter &#26159;&#21442;&#25968;&#21015;&#34920;&#65292;&#32780; body &#21017;&#26159;&#20989;&#25968;&#20307;&#12290;<code>fn<\/code>&#20851;&#38190;&#35789;&#65292;&#25324;&#21495;&#20869;&#20026;&#21442;&#25968;&#21015;&#34920;&#12290;<code>=&gt;<\/code>&#31661;&#22836;&#31526;&#21495;&#21644;&#26500;&#25104;&#20989;&#25968;&#20027;&#20307;&#30340;&#34920;&#36798;&#24335;&#12290;&#36820;&#22238;&#20540;&#38544;&#24335;&#23384;&#22312;&#65292;&#22240;&#27492;&#26080;&#38656;&#26174;&#24335;&#22768;&#26126;&#36820;&#22238;&#35821;&#21477;&#12290;<\/p>\n<p>&#35753;&#25105;&#20204;&#28145;&#20837;&#25506;&#35752;&#31661;&#22836;&#20989;&#25968;&#30340;&#19981;&#21516;&#29305;&#24449;&#21644;&#24494;&#22937;&#20043;&#22788;&#65292;&#37325;&#28857;&#25918;&#22312;&#23454;&#38469;&#20195;&#30721;&#31034;&#20363;&#19978;&#12290;&#38543;&#30528;&#25105;&#20204;&#20174;&#22522;&#30784;&#21040;&#39640;&#32423;&#22330;&#26223;&#30340;&#36827;&#23637;&#65292;&#24744;&#23558;&#33719;&#24471;&#22312;PHP&#20013;&#26377;&#25928;&#20351;&#29992;&#31661;&#22836;&#20989;&#25968;&#26102;&#26356;&#28145;&#23618;&#27425;&#30340;&#29702;&#35299;&#12290;<\/p>\n<h3>&#22522;&#26412;&#31661;&#22836;&#20989;&#25968;&#31034;&#20363;<\/h3>\n<p>&#22312;&#26368;&#31616;&#21333;&#30340;&#24418;&#24335;&#19979;&#65292;&#31661;&#22836;&#20989;&#25968;&#21487;&#20197;&#27809;&#26377;&#21442;&#25968;&#24182;&#30452;&#25509;&#36820;&#22238;&#19968;&#20010;&#20540;&#12290;&#32771;&#34385;&#20197;&#19979;&#31034;&#20363;&#65306;<\/p>\n<pre><code>\n$greet = fn() =&gt; 'Hello, World!';\n\necho $greet(); \/\/ Outputs: Hello, World!\n<\/code><\/pre>\n<p>&#36825;&#20010;&#20363;&#23376;&#23637;&#31034;&#20102;&#31661;&#22836;&#20989;&#25968;&#30340;&#31616;&#27905;&#24615;&#65292;&#20026;&#31616;&#21333;&#30340;&#25805;&#20316;&#25552;&#20379;&#20102;&#20256;&#32479;&#21311;&#21517;&#20989;&#25968;&#30340;&#32477;&#20339;&#26367;&#20195;&#26041;&#26696;&#12290;<\/p>\n<h3>&#20351;&#29992;&#21442;&#25968;<\/h3>\n<p>&#19982;&#20256;&#32479;&#30340;&#21311;&#21517;&#20989;&#25968;&#19968;&#26679;&#65292;&#31661;&#22836;&#20989;&#25968;&#20063;&#21487;&#20197;&#25509;&#21463;&#21442;&#25968;&#12290;&#20197;&#19979;&#31034;&#20363;&#28436;&#31034;&#20102;&#19968;&#20010;&#25509;&#21463;&#20004;&#20010;&#21442;&#25968;&#24182;&#36820;&#22238;&#23427;&#20204;&#20043;&#21644;&#30340;&#31661;&#22836;&#20989;&#25968;&#65306;<\/p>\n<pre><code>\n$add = fn($a, $b) =&gt; $a + $b;\n\necho $add(5, 10); \/\/ Outputs: 15\n<\/code><\/pre>\n<h3>&#33539;&#22260;&#21644;&#21464;&#37327;&#32487;&#25215;<\/h3>\n<p>&#31661;&#22836;&#20989;&#25968;&#30340;&#19968;&#20010;&#26174;&#33879;&#20248;&#21183;&#26159;&#21487;&#20197;&#32487;&#25215;&#29238;&#20316;&#29992;&#22495;&#20013;&#30340;&#21464;&#37327;&#65292;&#36825;&#31181;&#29305;&#24615;&#34987;&#31216;&#20026;&#35789;&#27861;&#20316;&#29992;&#22495;&#12290;&#19982;&#20256;&#32479;&#21311;&#21517;&#20989;&#25968;&#19981;&#21516;&#30340;&#26159;&#65292;&#21518;&#32773;&#38656;&#35201;&#20351;&#29992; this &#20851;&#38190;&#23383;&#26469;&#35775;&#38382;&#22806;&#37096;&#20316;&#29992;&#22495;&#30340;&#21464;&#37327;&#12290;<code>use<\/code>&#32487;&#25215;&#21464;&#37327;&#30340;&#20851;&#38190;&#23383;&#65292;&#31661;&#22836;&#20989;&#25968;&#20250;&#33258;&#21160;&#36825;&#26679;&#20570;&#12290;<\/p>\n<pre><code>\n$factor = 10;\n\n$multiplier = fn($number) =&gt; $number * $factor;\n\necho $multiplier(5); \/\/ Outputs: 50\n<\/code><\/pre>\n<p>&#22312;&#36825;&#19968;&#20363;&#23376;&#20013;&#65292;<code>$factor<\/code>&#22312;&#31661;&#22836;&#20989;&#25968;&#20869;&#37096;&#33258;&#21160;&#21487;&#35775;&#38382;&#65292;&#31616;&#21270;&#20102;&#20989;&#25968;&#35821;&#27861;&#24182;&#28040;&#38500;&#20102;&#38656;&#35201;&#20351;&#29992;&#30340;this&#20851;&#38190;&#23383;&#12290;<code>use<\/code>&#20851;&#38190;&#35789;&#12290;<\/p>\n<h3>&#31867;&#22411;&#25552;&#31034;&#21644;&#36820;&#22238;&#31867;&#22411;<\/h3>\n<p>&#31661;&#22836;&#20989;&#25968;&#36824;&#25903;&#25345;&#21442;&#25968;&#31867;&#22411;&#25552;&#31034;&#21644;&#25351;&#23450;&#36820;&#22238;&#31867;&#22411;&#65292;&#36825;&#22686;&#24378;&#20102;&#20989;&#25968;&#30340;&#21487;&#35835;&#24615;&#21644;&#20581;&#22766;&#24615;&#12290;&#20197;&#19979;&#26159;&#31034;&#20363;&#65306;<\/p>\n<pre><code>\n$concatenate = fn(string $a, string $b): string =&gt; $a . ' ' . $b;\n\necho $concatenate(\"Arrow\", \"Functions\"); \/\/ Outputs: Arrow Functions\n<\/code><\/pre>\n<h3>&#39640;&#32423;&#29992;&#27861;&#65306;&#25968;&#32452;&#26144;&#23556;<\/h3>\n<p>&#31661;&#22836;&#20989;&#25968;&#22312;&#25968;&#32452;&#26144;&#23556;&#21644;&#27714;&#21644;&#31561;&#22330;&#26223;&#19979;&#38750;&#24120;&#26377;&#29992;&#12290;&#20197;&#19979;&#26159;&#22914;&#20309;&#20351;&#29992;&#31661;&#22836;&#20989;&#25968;&#30340;&#19968;&#20010;&#20363;&#23376;&#65306;<code>array_map<\/code>&#65306;<\/p>\n<pre><code>\n$numbers = [1, 2, 3, 4, 5];\n\n$squaredNumbers = array_map(fn($number) =&gt; $number ** 2, $numbers);\n\nprint_r($squaredNumbers); \/\/ Outputs: Array ( [0] =&gt; 1 [1] =&gt; 4 [2] =&gt; 9 [3] =&gt; 16 [4] =&gt; 25 )\n<\/code><\/pre>\n<h3>&#22788;&#29702;&#22797;&#26434;&#26465;&#20214;&#21644;&#25805;&#20316;<\/h3>\n<p>&#23613;&#31649;&#31661;&#22836;&#20989;&#25968;&#26088;&#22312;&#31616;&#27905;&#26126;&#20102;&#65292;&#20294;&#23427;&#20204;&#21487;&#20197;&#22788;&#29702;&#22797;&#26434;&#30340;&#26465;&#20214;&#21644;&#25805;&#20316;&#65292;&#22914;&#26524;&#38656;&#35201;&#30340;&#35805;&#12290;&#20197;&#19979;&#31034;&#20363;&#20351;&#29992;&#31661;&#22836;&#20989;&#25968;&#20013;&#30340;&#19977;&#20803;&#36816;&#31639;&#31526;&#36827;&#34892;&#22522;&#26412;&#30340;&#26465;&#20214;&#26816;&#26597;&#65306;<\/p>\n<pre><code>\n$isEven = fn($number) =&gt; $number % 2 === 0 ? 'Even' : 'Odd';\n\n$result = $isEven(4); \/\/ Outputs: Even\n\n$result = $isEven(5); \/\/ Outputs: Odd\n<\/code><\/pre>\n<p>&#22987;&#32456;&#35760;&#20303;&#65292;&#20445;&#25345;&#31661;&#22836;&#20989;&#25968;&#31616;&#21333;&#26126;&#20102;&#19988;&#26131;&#20110;&#29702;&#35299;&#33267;&#20851;&#37325;&#35201;&#12290;&#36991;&#20813;&#36807;&#24230;&#22797;&#26434;&#21270;&#31661;&#22836;&#20989;&#25968;&#20197;&#20445;&#25345;&#20195;&#30721;&#28165;&#26224;&#26131;&#25026;&#12290;<\/p>\n<h3>&#20351;&#29992;&#31661;&#22836;&#20989;&#25968;&#36827;&#34892;&#23884;&#22871;&#25805;&#20316;&#12290;<\/h3>\n<p>&#31661;&#22836;&#20989;&#25968;&#20063;&#21487;&#20197;&#23884;&#22871;&#22312;&#20854;&#20182;&#31661;&#22836;&#20989;&#25968;&#20869;&#37096;&#12290;&#36825;&#22312;&#38656;&#35201;&#22810;&#37325;&#23618;&#32423;&#30340;&#20989;&#25968;&#25277;&#35937;&#26102;&#38750;&#24120;&#26377;&#29992;&#65306;<\/p>\n<pre><code>\n$adderFactory = fn($x) =&gt; fn($y) =&gt; $x + $y;\n\n$addFive = $adderFactory(5);\necho $addFive(10); \/\/ Outputs: 15\n<\/code><\/pre>\n<p>&#36825;&#21487;&#20197;&#23548;&#33268;&#26356;&#39640;&#32423;&#30340;&#20989;&#25968;&#24335;&#32534;&#31243;&#27010;&#24565;&#65292;&#20801;&#35768;&#21019;&#24314;&#39640;&#38454;&#20989;&#25968;&#21644;&#37096;&#20998;&#24212;&#29992;&#22312;PHP&#20013;&#12290;<\/p>\n<h2>&#26368;&#20339;&#23454;&#36341;<\/h2>\n<p>&#34429;&#28982;&#31661;&#22836;&#20989;&#25968;&#24102;&#26469;&#20102;&#35768;&#22810;&#20415;&#21033;&#65292;&#20294;&#24517;&#39035;&#35880;&#24910;&#20351;&#29992;&#65306;<\/p>\n<p>&#35760;&#24471;&#31661;&#22836;&#20989;&#25968;&#26377;&#26126;&#30830;&#30340;&#35789;&#27861;&#20316;&#29992;&#22495;&#32487;&#25215;&#65292;&#22240;&#27492;&#23427;&#20204;&#38750;&#24120;&#36866;&#21512;&#38656;&#35201;&#35775;&#38382;&#29238;&#20316;&#29992;&#22495;&#21464;&#37327;&#30340;&#24773;&#20917;&#12290;<\/p>\n<p>&#36991;&#20813;&#20351;&#29992;&#38271;&#25110;&#22797;&#26434;&#30340;&#31661;&#22836;&#20989;&#25968;&#65292;&#22240;&#20026;&#36825;&#21487;&#33021;&#20250;&#38477;&#20302;&#20195;&#30721;&#30340;&#21487;&#35835;&#24615;&#12290;<\/p>\n<p>&#24403;&#20989;&#25968;&#36923;&#36753;&#31616;&#21333;&#21040;&#21487;&#20197;&#34920;&#36798;&#22312;&#19968;&#20010;&#21333;&#20010;&#34920;&#36798;&#24335;&#20013;&#26102;&#65292;&#20351;&#29992;&#31661;&#22836;&#20989;&#25968;&#12290;<\/p>\n<h2>&#32467;&#35770;&#12290;<\/h2>\n<p>&#24635;&#20043;&#65292;PHP&#30340;&#31661;&#22836;&#20989;&#25968;&#26159;&#19968;&#31181;&#32039;&#20945;&#19988;&#34920;&#36798;&#21147;&#24378;&#30340;&#21151;&#33021;&#65292;&#36866;&#29992;&#20110;&#38656;&#35201;&#31616;&#30701;&#12289;&#19968;&#34892;&#20195;&#30721;&#30340;&#20989;&#25968;&#25110;&#38381;&#21253;&#30340;&#24773;&#26223;&#65292;&#23588;&#20854;&#26159;&#22312;&#22788;&#29702;&#25968;&#32452;&#20989;&#25968;&#25110;&#31616;&#21333;&#22238;&#35843;&#26102;&#12290;&#23427;&#20204;&#31616;&#21270;&#20102;&#35821;&#27861;&#24182;&#22686;&#24378;&#20102;&#21487;&#35835;&#24615;&#65292;&#21069;&#25552;&#26159;&#20351;&#29992;&#24471;&#24403;&#12290;&#23601;&#20687;&#20219;&#20309;&#35821;&#35328;&#29305;&#24615;&#19968;&#26679;&#65292;&#20851;&#38190;&#26159;&#29702;&#35299;&#20309;&#26102;&#20309;&#22320;&#26377;&#25928;&#22320;&#20351;&#29992;&#23427;&#26469;&#32534;&#20889;&#25972;&#27905;&#12289;&#21487;&#32500;&#25252;&#30340;&#20195;&#30721;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#27010;&#35272; &#31661;&#22836;&#20989;&#25968;&#65292;&#22312;PHP 7.4&#20013;&#24341;&#20837;&#65292;&#25552;&#20379;&#20102;&#19968;&#31181;&#26356;&#31616;..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-443","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\/443","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=443"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=443"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=443"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=443"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}