{"id":431,"date":"2025-06-10T20:21:11","date_gmt":"2025-06-10T12:21:11","guid":{"rendered":"https:\/\/www.zhaozhao123.cn\/php\/php-application-manual\/jcyy\/431.html"},"modified":"2025-06-10T20:21:11","modified_gmt":"2025-06-10T12:21:11","slug":"php%e4%b8%ad%e7%9a%84%e9%ab%98%e9%98%b6%e5%87%bd%e6%95%b0%ef%bc%9a%e5%ae%9e%e7%94%a8%e6%8c%87%e5%8d%97%ef%bc%886%e4%b8%aa%e5%ae%9e%e4%be%8b%ef%bc%89","status":"publish","type":"my1js","link":"https:\/\/www.zhaozhao123.cn\/php\/my1js\/431.html","title":{"rendered":"PHP\u4e2d\u7684\u9ad8\u9636\u51fd\u6570\uff1a\u5b9e\u7528\u6307\u5357\uff086\u4e2a\u5b9e\u4f8b\uff09"},"content":{"rendered":"<p><body><\/p>\n<h2>&#27010;&#35272;<\/h2>\n<p>&#39640;&#38454;&#20989;&#25968;&#22312;&#29616;&#20195;PHP&#32534;&#31243;&#20013;&#21344;&#25454;&#30528;&#22522;&#30707;&#65292;&#26497;&#22823;&#22320;&#25552;&#39640;&#20102;&#24320;&#21457;&#20154;&#21592;&#32534;&#20889;&#31616;&#27905;&#19988;&#21151;&#33021;&#24615;&#24378;&#20195;&#30721;&#30340;&#26041;&#24335;&#12290;&#26412;&#25351;&#21335;&#23558;&#25506;&#35752;&#20160;&#20040;&#26159;&#39640;&#38454;&#20989;&#25968;&#20197;&#21450;&#22914;&#20309;&#21033;&#29992;&#23427;&#20204;&#22312;PHP&#20013;&#31616;&#21270;&#20195;&#30721;&#24211;&#65292;&#36890;&#36807;&#23454;&#29992;&#30340;&#12289;&#23454;&#38469;&#30340;&#20363;&#23376;&#36827;&#34892;&#35828;&#26126;&#12290;<\/p>\n<h2>&#29702;&#35299;&#39640;&#38454;&#20989;&#25968;<\/h2>\n<p>&#39640;&#38454;&#20989;&#25968;&#26159;&#19968;&#31181;&#26082;&#21487;&#20197;&#20316;&#20026;&#21442;&#25968;&#20256;&#36882;&#65292;&#20063;&#21487;&#20197;&#36820;&#22238;&#20989;&#25968;&#30340;&#20989;&#25968;&#12290;PHP &#25552;&#20379;&#20102;&#22810;&#31181;&#20869;&#32622;&#30340;&#39640;&#38454;&#20989;&#25968;&#26469;&#22788;&#29702;&#25968;&#32452;&#65292;&#20363;&#22914;&#65306;<code>array_map()<\/code>&#22909;&#30340;&#65292;&#35831;&#21457;&#36865;&#20320;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<code>array_filter()<\/code>&#21644;&#20320;&#25171;&#25307;&#21628;&#12290;<code>array_reduce()<\/code>&#65292;&#36824;&#26377;usort()&#36827;&#34892;&#25490;&#24207;&#12290;<\/p>\n<p>&#31034;&#20363; 1&#65306;&#20351;&#29992; array_map()<\/p>\n<pre><code>$numbers = [1, 2, 3, 4, 5];\n$squared = array_map(fn($number) =&gt; $number ** 2, $numbers);\nprint_r($squared);\n<\/code><\/pre>\n<p>&#22909;&#30340;&#65292;&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p>\n<pre><code>Array\n(\n    [0] =&gt; 1\n    [1] =&gt; 4\n    [2] =&gt; 9\n    [3] =&gt; 16\n    [4] =&gt; 25\n)\n<\/code><\/pre>\n<p>&#31034;&#20363; 2&#65306;&#20351;&#29992; array_filter()<\/p>\n<pre><code>$numbers = [1, 'two', 3, 'four', 5];\n$integers = array_filter($numbers, 'is_int');\nprint_r($integers);\n<\/code><\/pre>\n<p>&#22909;&#30340;&#65292;&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p>\n<pre><code>Array\n(\n    [0] =&gt; 1\n    [2] =&gt; 3\n    [4] =&gt; 5\n)\n<\/code><\/pre>\n<p>&#31034;&#20363; 3&#65306;&#20351;&#29992; array_reduce()<\/p>\n<pre><code>$numbers = [1, 2, 3, 4, 5];\n$sum = array_reduce($numbers, fn($carry, $item) =&gt; $carry + $item, 0);\necho $sum;\n<\/code><\/pre>\n<p>&#22909;&#30340;&#65292;&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p>\n<pre><code>15\n<\/code><\/pre>\n<h2>&#21019;&#24314;&#33258;&#23450;&#20041;&#39640;&#38454;&#20989;&#25968;<\/h2>\n<p>&#20320;&#21487;&#20197;&#19981;&#23616;&#38480;&#20110;&#20869;&#32622;&#20989;&#25968;&#65292;&#21487;&#20197;&#21019;&#24314;&#33258;&#24049;&#30340;&#39640;&#38454;&#20989;&#25968;&#12290;&#20363;&#22914;&#65292;&#22914;&#26524;&#20320;&#24819;&#21019;&#24314;&#19968;&#20010;&#20989;&#25968;&#26469;&#23545;&#25968;&#32452;&#20013;&#30340;&#25152;&#26377;&#20803;&#32032;&#24212;&#29992;&#33258;&#23450;&#20041;&#25805;&#20316;&#65306;<\/p>\n<p>&#31034;&#20363; 4&#65306;&#33258;&#23450;&#20041;&#39640;&#38454;&#20989;&#25968;<\/p>\n<pre><code>function array_apply($array, callable $operation) {\n    foreach ($array as $key =&gt; $value) {\n        $array[$key] = $operation($value);\n    }\n    return $array;\n}\n\n$numbers = [1, 2, 3, 4, 5];\n$incremented = array_apply($numbers, fn($n) =&gt; $n + 1);\nprint_r($incremented);\n<\/code><\/pre>\n<p>&#22909;&#30340;&#65292;&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p>\n<pre><code>Array\n(\n    [0] =&gt; 2\n    [1] =&gt; 3\n    [2] =&gt; 4\n    [3] =&gt; 5\n    [4] =&gt; 6\n)\n<\/code><\/pre>\n<h2>&#21033;&#29992;&#21311;&#21517;&#20989;&#25968;&#21644;&#38381;&#21253;<\/h2>\n<p>PHP &#25903;&#25345;&#21311;&#21517;&#20989;&#25968;&#65288;&#38381;&#21253;&#65289;&#65292;&#21363;&#39640;&#38454;&#20989;&#25968;&#65292;&#20351;&#22788;&#29702;&#22238;&#35843;&#20989;&#25968;&#21464;&#24471;&#26497;&#20854;&#31616;&#21333;&#12290;&#38381;&#21253;&#21487;&#20197;&#25429;&#33719;&#29238;&#20316;&#29992;&#22495;&#20013;&#30340;&#21464;&#37327;&#65292;&#20174;&#32780;&#22312;&#22238;&#35843;&#20989;&#25968;&#20013;&#25552;&#20379;&#28789;&#27963;&#24615;&#21644;&#24378;&#22823;&#24615;&#12290;<\/p>\n<p>&#31034;&#20363; 5&#65306;&#20351;&#29992;&#20851;&#38190;&#23383; use &#30340;&#38381;&#21253;<\/p>\n<pre><code>$multiplier = 3;\n$numbers = [1, 2, 3, 4, 5];\n$scaled = array_map(fn($n) =&gt; $n * $multiplier, $numbers);\nprint_r($scaled);\n<\/code><\/pre>\n<p>&#22909;&#30340;&#65292;&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p>\n<pre><code>Array\n(\n    [0] =&gt; 3\n    [1] =&gt; 6\n    [2] =&gt; 9\n    [3] =&gt; 12\n    [4] =&gt; 15\n)\n<\/code><\/pre>\n<h2>&#39640;&#32423;&#27169;&#24335;&#19982;&#39640;&#38454;&#20989;&#25968;<\/h2>\n<p>&#32467;&#21512;&#22810;&#20010;&#39640;&#38454;&#20989;&#25968;&#21487;&#20197;&#20135;&#29983;&#24378;&#22823;&#30340;&#25968;&#25454;&#22788;&#29702;&#27169;&#24335;&#12290;&#20363;&#22914;&#65292;&#20320;&#21487;&#20197;&#32452;&#21512;<code>array_map()<\/code>&#21644;&#25105;&#26377;&#20160;&#20040;&#20107;&#21527;&#65311;<code>array_filter()<\/code>&#39318;&#20808;&#23545;&#25968;&#32452;&#36827;&#34892;&#36716;&#25442;&#65292;&#28982;&#21518;&#36807;&#28388;&#23427;&#12290;<\/p>\n<p>&#31034;&#20363; 6&#65306;&#38142;&#24335;&#35843;&#29992;&#39640;&#38454;&#20989;&#25968;<\/p>\n<pre><code>$numbers = [1, 2, 3, 4, 5];\n$oddCubed = array_filter(\n    array_map(fn($n) =&gt; $n ** 3, $numbers),\n    fn($n) =&gt; $n % 2 !== 0\n);\nprint_r($oddCubed);\n<\/code><\/pre>\n<p>&#22909;&#30340;&#65292;&#35831;&#25552;&#20379;&#38656;&#35201;&#32763;&#35793;&#30340;&#20869;&#23481;&#12290;<\/p>\n<pre><code>Array\n(\n    [0] =&gt; 1\n    [2] =&gt; 27\n    [4] =&gt; 125\n)\n<\/code><\/pre>\n<h2>&#32467;&#35770;<\/h2>\n<p>&#39640;&#32423;&#20989;&#25968;&#25552;&#20379;&#20102;&#19968;&#20010;&#24378;&#22823;&#30340;&#26694;&#26550;&#65292;&#29992;&#20110;&#20197;&#20989;&#25968;&#24335;&#39118;&#26684;&#25805;&#20316;&#25968;&#25454;&#38598;&#21512;&#65292;&#22312;PHP&#20013;&#12290;&#36890;&#36807;&#29702;&#35299;&#21644;&#24212;&#29992;&#23427;&#20204;&#65292;&#20320;&#21487;&#20197;&#32534;&#20889;&#26356;&#26131;&#35835;&#12289;&#26356;&#20855;&#34920;&#36798;&#21147;&#21644;&#21487;&#32500;&#25252;&#24615;&#30340;&#20195;&#30721;&#12290;&#25317;&#25265;&#36825;&#20123;&#24037;&#20855;&#65292;&#35753;&#20320;&#30340;PHP&#32534;&#31243;&#36798;&#21040;&#26032;&#30340;&#39640;&#24230;&#12290;<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#27010;&#35272; &#39640;&#38454;&#20989;&#25968;&#22312;&#29616;&#20195;PHP&#32534;&#31243;&#20013;&#21344;&#25454;&#30528;&#22522;&#30707;&#65292;&#26497;&#038;#22..<\/p>\n","protected":false},"author":1,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false},"tags":[],"my1js2nav":[38],"tuisongtax":[],"class_list":["post-431","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\/431","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=431"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tags?post=431"},{"taxonomy":"my1js2nav","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/my1js2nav?post=431"},{"taxonomy":"tuisongtax","embeddable":true,"href":"https:\/\/www.zhaozhao123.cn\/php\/wp-json\/wp\/v2\/tuisongtax?post=431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}