{"id":424,"date":"2025-06-10T20:15:17","date_gmt":"2025-06-10T12:15:17","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/424.html"},"modified":"2025-06-10T20:15:17","modified_gmt":"2025-06-10T12:15:17","slug":"%e5%9c%a8php%e4%b8%ad%e4%bd%bf%e7%94%a8%e5%8c%bf%e5%90%8d%e5%87%bd%e6%95%b0","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/424.html","title":{"rendered":"\u5728PHP\u4e2d\u4f7f\u7528\u533f\u540d\u51fd\u6570"},"content":{"rendered":"<p><body><\/p>\n<h2>&#20171;&#32461;<\/h2>\n<p>&#21311;&#21517;&#20989;&#25968;&#65292;&#20063;&#31216;&#20026;&#38381;&#21253;&#65292;&#22312;PHP&#20013;&#20855;&#26377;&#26080;&#25351;&#23450;&#21517;&#31216;&#30340;&#21151;&#33021;&#12290;&#23427;&#20204;&#33021;&#22815;&#25552;&#20379;&#26356;&#24555;&#21644;&#26356;&#21160;&#24577;&#30340;&#32534;&#31243;&#33021;&#21147;&#65292;&#29305;&#21035;&#26159;&#22312;&#22238;&#35843;&#21644;&#20107;&#20214;&#39537;&#21160;&#20195;&#30721;&#20013;&#29305;&#21035;&#26377;&#20215;&#20540;&#12290;<\/p>\n<h2>&#21311;&#21517;&#20989;&#25968;&#30340;&#22522;&#26412;&#29992;&#27861;<\/h2>\n<p>&#21311;&#21517;&#20989;&#25968;&#20351;&#29992;&#21311;&#21517;&#20989;&#25968;&#23450;&#20041;&#12290;<code>function<\/code>&#20851;&#38190;&#35789;&#65292;&#25324;&#21495;&#20869;&#26080;&#21517;&#65306;<\/p>\n<pre><code>$greet = function($name) {\n    echo \"Hello, {$name}!\";\n};\n$greet(\"World\");\n<\/code><\/pre>\n<p>&#35813;&#20195;&#30721;&#23450;&#20041;&#20102;&#19968;&#20010;&#20989;&#25968;&#65292;&#21521;&#29992;&#25143;&#25171;&#25307;&#21628;&#65292;&#24182;&#23558;&#20854;&#36171;&#20540;&#32473;&#21464;&#37327;&#12290;<code>$greet<\/code>&#35201;&#35843;&#29992;&#35813;&#20989;&#25968;&#65292;&#21482;&#38656;&#23558;&#21464;&#37327;&#20316;&#20026;&#20989;&#25968;&#35843;&#29992;&#26469;&#20351;&#29992;&#21363;&#21487;&#12290;<\/p>\n<h2>&#20256;&#36882;&#21464;&#37327;&#21040;&#20351;&#29992;&#35821;&#21477;<\/h2>\n<p>&#21311;&#21517;&#20989;&#25968;&#21487;&#20197;&#32487;&#25215;&#29238;&#20316;&#29992;&#22495;&#20013;&#30340;&#21464;&#37327;&#20351;&#29992;&#22914;&#19979;&#35821;&#27861;&#65306;var x = 10; (function(){&#8230;})(x);<code>use<\/code>&#20851;&#38190;&#35789;&#65306;<\/p>\n<pre><code>$greeting = 'Hello';\n$greet = function($name) use ($greeting) {\n    echo \"{$greeting}, {$name}!\";\n};\n$greet(\"World\");\n<\/code><\/pre>\n<p>&#23545;&#19981;&#36215;&#65292;&#25105;&#27809;&#26126;&#30333;&#20320;&#22312;&#35828;&#20160;&#20040;&#12290;<code>$greeting<\/code>&#21442;&#25968;&#20256;&#36882;&#32473;&#38381;&#21253;&#20351;&#29992;&#30340;&#26159;&#21442;&#25968;&#12290;<code>use<\/code>&#26465;&#27454;&#65292;&#20351;&#20854;&#22312;&#21151;&#33021;&#20869;&#21487;&#29992;&#12290;<\/p>\n<h2>&#21311;&#21517;&#20989;&#25968;&#20316;&#20026;&#22238;&#35843;&#20989;&#25968;<\/h2>\n<p>&#21311;&#21517;&#20989;&#25968;&#22312;&#20687;&#22238;&#35843;&#20989;&#25968;&#36825;&#26679;&#30340;&#22330;&#26223;&#19979;&#38750;&#24120;&#26377;&#29992;&#12290;<code>array_map<\/code>&#20320;&#22909;&#65281;&#26377;&#20160;&#20040;&#25105;&#21487;&#20197;&#24110;&#21161;&#20320;&#30340;&#21527;&#65311;<\/p>\n<pre><code>$numbers = [1, 2, 3, 4];\n$doubled = array_map(function($number) {\n    return $number * 2;\n}, $numbers);\nprint_r($doubled);\n<\/code><\/pre>\n<p>&#19978;&#36848;&#20195;&#30721;&#29255;&#27573;&#23545;&#25968;&#32452;&#20013;&#30340;&#27599;&#20010;&#20803;&#32032;&#24212;&#29992;&#21311;&#21517;&#20989;&#25968;&#12290;<code>$numbers<\/code>&#25968;&#32452;&#65292;&#36820;&#22238;&#19968;&#20010;&#25968;&#20540;&#30340;&#25968;&#32452;&#12290;<\/p>\n<h2>&#36820;&#22238;&#21311;&#21517;&#20989;&#25968;<\/h2>\n<p>&#21311;&#21517;&#20989;&#25968;&#21487;&#20197;&#29992;&#26469;&#21019;&#24314;&#24037;&#21378;&#20989;&#25968;&#65292;&#35813;&#24037;&#21378;&#20989;&#25968;&#36820;&#22238;&#20854;&#20182;&#20989;&#25968;&#65306;<\/p>\n<pre><code>function multiplier($factor) {\n    return function($num) use ($factor) {\n        return $num * $factor;\n    };\n}\n$double = multiplier(2);\necho $double(5); \/\/ Outputs: 10\n<\/code><\/pre>\n<p>A<code>multiplier<\/code>&#20989;&#25968;&#36820;&#22238;&#21478;&#19968;&#20010;&#20989;&#25968;&#65292;&#35813;&#20989;&#25968;&#20250;&#23558;&#36755;&#20837;&#30340;&#25968;&#23383;&#20056;&#20197;&#19968;&#20010;&#32473;&#23450;&#30340;&#22240;&#23376;&#65288;&#22312;&#27492;&#20363;&#20013;&#20026;&#20004;&#20493;&#65289;&#12290;<\/p>\n<h2>&#39640;&#32423;&#20351;&#29992;&#22312;&#23545;&#35937;&#19978;<\/h2>\n<p>&#22312;&#23545;&#35937;&#19978;&#19979;&#25991;&#20013;&#65292;&#21311;&#21517;&#20989;&#25968;&#21487;&#20197;&#20316;&#20026;&#26041;&#27861;&#20351;&#29992;&#25110;&#32465;&#23450;&#21040;&#23545;&#35937;&#19978;&#65306;<\/p>\n<pre><code>class Greeter {\n    public $greeting = 'Hello';\n}\n\n$greeter = new Greeter();\n$helloWorld = function($name) {\n    echo \"{$this-&gt;greeting}, {$name}!\";\n};\n\n$boundHelloWorld = $helloWorld-&gt;bindTo($greeter, 'Greeter');\n$boundHelloWorld(\"World\");\n<\/code><\/pre>\n<p>&#22312;&#36825;&#20010;&#20363;&#23376;&#20013;&#65292;<code>$helloWorld<\/code>&#21311;&#21517;&#20989;&#25968;&#20351;&#29992;&#20102;&#20160;&#20040;&#65311;<code>$this<\/code>&#23427;&#22312;&#26410;&#32465;&#23450;&#21040;&#31867;&#30340;&#23545;&#35937;&#26102;&#24182;&#19981;&#23450;&#20041;&#12290;<code>Greeter<\/code>&#24050;&#32463;&#25910;&#21040;&#65292;&#35831;&#38382;&#26377;&#20160;&#20040;&#25105;&#21487;&#20197;&#24110;&#21161;&#30340;&#21527;&#65311;<\/p>\n<h2>&#20351;&#29992;&#25968;&#32452;&#20989;&#25968;&#25805;&#20316;&#25968;&#32452;<\/h2>\n<p>&#32467;&#21512;&#25968;&#32452;&#20989;&#25968;&#21644;&#21311;&#21517;&#20989;&#25968;&#21487;&#20197;&#23454;&#29616;&#24378;&#22823;&#30340;&#25968;&#32452;&#25805;&#20316;&#65306;<\/p>\n<pre><code>$students = [\n    ['name' =&gt; 'Alice', 'score' =&gt; 9.8],\n    ['name' =&gt; 'Bob', 'score' =&gt; 7.3],\n    ['name' =&gt; 'Charlie', 'score' =&gt; 6.9],\n];\nusort($students, function($a, $b) {\n    return $a['score'] &lt;$ b['score'];\n});\nprint_r($students);\n<\/code><\/pre>\n<p>&#26681;&#25454;&#24744;&#25552;&#20379;&#30340;&#20195;&#30721;&#65292;&#23427;&#23545;&#25968;&#32452;&#36827;&#34892;&#20102;&#25490;&#24207;&#12290;<code>$students<\/code>by themselves<code>score<\/code>&#20351;&#29992;&#23646;&#24615;&#30340;&#26041;&#27861;&#12290;<code>usort<\/code>&#20989;&#25968;&#21644;&#19968;&#20010;&#36866;&#24403;&#30340;&#27604;&#36739;&#21311;&#21517;&#20989;&#25968;&#12290;<\/p>\n<h2>&#20351;&#29992;&#21311;&#21517;&#20989;&#25968;&#19982;PHP&#20869;&#32622;&#25509;&#21475;<\/h2>\n<p>&#21311;&#21517;&#20989;&#25968;&#21487;&#20197;&#36716;&#25442;&#20026;&#23454;&#20363;&#12290;<code>Closure<\/code>&#22312;PHP&#20013;&#65292;&#29992;&#20110;&#35843;&#29992;&#20989;&#25968;&#30340;&#20869;&#32622;&#25509;&#21475;&#26159;&#65306;callable<\/p>\n<pre><code>$adder = function($x, $y) {\n    return $x + $y;\n};\n$addition = $adder(1, 2);\necho $addition; \/\/ Outputs: 3\n<\/code><\/pre>\n<p>&#36825;&#20010;&#21151;&#33021;&#20801;&#35768;&#21311;&#21517;&#20989;&#25968;&#20256;&#36882;&#32473;&#38656;&#35201;&#23454;&#20363;&#30340;&#22320;&#26041;&#12290;<code>Closure<\/code>&#38656;&#35201;&#21487;&#35843;&#29992;&#30340;&#26041;&#27861;&#12290;<\/p>\n<h2>&#21311;&#21517;&#20989;&#25968;&#19982;&#29983;&#25104;&#22120;<\/h2>\n<p>&#21311;&#21517;&#20989;&#25968;&#21487;&#20197;&#19982;&#29983;&#25104;&#22120;&#19968;&#36215;&#20351;&#29992;&#65292;&#20197;&#22788;&#29702;&#25968;&#25454;&#36845;&#20195;&#65306;<\/p>\n<pre><code>$fibonacci = function($count) {\n    $first = 0;\n    $second = 1;\n    for($i = 0; $i &lt; $count; $i++) {\n        yield $first;\n        $next = $first + $second;\n        $first = $second;\n        $second = $next;\n    }\n};\nforeach($fibonacci(10) as $num) {\n    echo $num . ' ';\n}\n<\/code><\/pre>\n<p>&#36825;&#20010;&#29983;&#25104;&#22120;&#20135;&#29983;&#26000;&#27874;&#37027;&#22865;&#25968;&#21015;&#30340;&#21069;&#21313;&#20010;&#25968;&#23383;&#12290;<\/p>\n<h2>&#32467;&#35770;&#12290;<\/h2>\n<p>&#21311;&#21517;&#20989;&#25968;&#22312;PHP&#20013;&#25552;&#20379;&#20102;&#28789;&#27963;&#24615;&#21644;&#31616;&#27905;&#30340;&#35821;&#27861;&#65292;&#36866;&#29992;&#20110;&#21508;&#31181;&#22330;&#26223;&#22914;&#20107;&#20214;&#22788;&#29702;&#12289;&#25968;&#32452;&#25805;&#20316;&#21644;&#22238;&#35843;&#35774;&#35745;&#31561;&#12290;&#24403;&#20320;&#25317;&#25265;&#21311;&#21517;&#20989;&#25968;&#26102;&#65292;&#20320;&#20250;&#21457;&#29616;&#33258;&#24049;&#32534;&#20889;&#26356;&#26131;&#35835;&#19988;&#21487;&#32500;&#25252;&#30340;PHP&#20195;&#30721;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#20171;&#32461; &#21311;&#21517;&#20989;&#25968;&#65292;&#20063;&#31216;&#20026;&#38381;&#21253;&#65292;&#22312;PHP&#20013;&#20855;&#26377;&#26080;&#25351;&#038;#23..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-424","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\/424","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=424"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=424"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=424"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}