{"id":777,"date":"2024-11-07T16:25:16","date_gmt":"2024-11-07T08:25:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/777\/"},"modified":"2024-11-07T16:25:16","modified_gmt":"2024-11-07T08:25:16","slug":"php-%e5%87%bd%e6%95%b0%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f%e5%ba%94%e7%94%a8%e4%b8%8e%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/777\/","title":{"rendered":"PHP \u51fd\u6570\u8bbe\u8ba1\u6a21\u5f0f\u5e94\u7528\u4e0e\u6027\u80fd\u4f18\u5316"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1129\" src=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172854720386251.jpg\" width=\"720\" height=\"288\" srcset=\"https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172854720386251.jpg 720w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172854720386251-300x120.jpg 300w, https:\/\/fwq.ai\/blog\/wp-content\/uploads\/2024\/11\/172854720386251-670x268.jpg 670w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" title=\"PHP \u51fd\u6570\u8bbe\u8ba1\u6a21\u5f0f\u5e94\u7528\u4e0e\u6027\u80fd\u4f18\u5316\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u8bbe\u8ba1\u6a21\u5f0f\u5e94\u7528\u4e0e\u6027\u80fd\u4f18\u5316\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u8bbe\u8ba1\u6a21\u5f0f\u5e94\u7528\u4e0e\u6027\u80fd\u4f18\u5316<\/strong><\/p>\n<p>\u51fd\u6570\u8bbe\u8ba1\u6a21\u5f0f\u662f\u4e00\u79cd\u5c06\u51fd\u6570\u7ec4\u7ec7\u6210\u4e0d\u540c\u6a21\u5f0f\u7684\u5b9e\u8df5\uff0c\u65e8\u5728\u63d0\u9ad8\u4ee3\u7801\u53ef\u7ef4\u62a4\u6027\u3001\u7075\u6d3b\u6027\u548c\u6027\u80fd\u3002\u672c\u6587\u5c06\u63a2\u8ba8 PHP \u4e2d\u5e38\u89c1\u7684\u51fd\u6570\u8bbe\u8ba1\u6a21\u5f0f\u53ca\u5176\u5982\u4f55\u5e94\u7528\u4e8e\u4f18\u5316\u4ee3\u7801\u6027\u80fd\u3002<\/p>\n<p><strong>\u51fd\u6570\u94fe\u5f0f\u6a21\u5f0f<\/strong><\/p>\n<p>\u94fe\u5f0f\u6a21\u5f0f\u5141\u8bb8\u60a8\u5c06\u4e00\u8fde\u4e32\u51fd\u6570\u5e94\u7528\u4e8e\u540c\u4e00\u8f93\u5165\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8fde\u63a5\u51fd\u6570\u8fd4\u56de\u7684\u503c\u4e0e subsequent \u51fd\u6570\u7684\u8f93\u5165\u6765\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u94fe\u5f0f\u6a21\u5f0f\u5c06\u591a\u4e2a\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570\u5e94\u7528\u4e8e\u4e00\u4e2a\u5b57\u7b26\u4e32\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201cPHP\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b<\/p>\n<pre>$processedString = strtoupper($string)\n    -&amp;gt;replace(' ', '-')\n    -&amp;gt;substr(0, 10);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u67ef\u91cc\u5316<\/strong><\/p>\n<p>\u67ef\u91cc\u5316\u662f\u4e00\u79cd\u5c06\u591a\u53c2\u6570\u51fd\u6570\u8f6c\u6362\u4e3a\u4e00\u5e8f\u5217\u63a5\u53d7\u5355\u4e2a\u53c2\u6570\u7684\u51fd\u6570\u7684\u6280\u672f\u3002\u8fd9\u6709\u52a9\u4e8e\u63d0\u9ad8\u7075\u6d3b\u6027\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u60a8\u90e8\u5206\u5e94\u7528\u51fd\u6570\u5e76\u7a0d\u540e\u63d0\u4f9b\u5176\u4f59\u53c2\u6570\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u53ef\u4ee5\u4f7f\u7528\u67ef\u91cc\u5316\u521b\u5efa\u53ef\u91cd\u590d\u4f7f\u7528\u7684\u51fd\u6570\uff0c\u5982\u6570\u7ec4\u6620\u5c04\uff1a<\/p>\n<pre>$map = curry(function ($fn, $arr) { return array_map($fn, $arr); });\n$mappedArray = $map('strtoupper')(['foo', 'bar', 'baz']);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5907\u5fd8\u5f55\u6a21\u5f0f<\/strong><\/p>\n<p>\u5907\u5fd8\u5f55\u6a21\u5f0f\u901a\u8fc7\u7f13\u5b58\u51fd\u6570\u7ed3\u679c\u6765\u63d0\u9ad8\u6027\u80fd\u3002\u8fd9\u5bf9\u4e8e\u4ee3\u4ef7\u6602\u8d35\u6216\u8ba1\u7b97\u5bc6\u96c6\u578b\u7684\u51fd\u6570\u5c24\u5176\u6709\u7528\u3002\u8981\u5b9e\u73b0\u5907\u5fd8\u5f55\u6a21\u5f0f\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u68c0\u67e5\u7f13\u5b58\u5e76\u53ea\u6709\u5728\u7f13\u5b58\u65e0\u6548\u65f6\u624d\u8ba1\u7b97\u7ed3\u679c\u3002<\/p>\n<pre>function fibonacci($n) {\n    static $memo = [];\n\n    if (!isset($memo[$n])) {\n        $memo[$n] = $n &lt;p&gt;&lt;strong&gt;\u5b9e\u6218\u6848\u4f8b&lt;\/strong&gt;&lt;\/p&gt;&lt;p&gt;&lt;strong&gt;\u6848\u4f8b 1\uff1a\u4f18\u5316\u5b57\u7b26\u4e32\u5904\u7406&lt;\/strong&gt;&lt;\/p&gt;&lt;p&gt;\u4f7f\u7528\u94fe\u5f0f\u6a21\u5f0f\u53ef\u4ee5\u4f18\u5316\u5b57\u7b26\u4e32\u5904\u7406\u4efb\u52a1\uff0c\u51cf\u5c11\u51fd\u6570\u8c03\u7528\u6570\u91cf\u5e76\u63d0\u9ad8\u53ef\u8bfb\u6027\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c06\u591a\u4e2a\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570\u94fe\u5f0f\u5316\u6765\u521b\u5efa\u53ef\u91cd\u590d\u4f7f\u7528\u7684\u5b57\u7b26\u4e32\u6e05\u7406\u5de5\u5177\u3002&lt;\/p&gt;&lt;pre class=\"brush:php;toolbar:false;\"&gt;function cleanString($string) {\n    return $string\n        -&amp;gt;replace(' ', '-')\n        -&amp;gt;replace('!', '')\n        -&amp;gt;replace('?', '')\n        -&amp;gt;strtolower();\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6848\u4f8b 2\uff1a\u63d0\u9ad8\u6570\u7ec4\u6620\u5c04\u6027\u80fd<\/strong><\/p>\n<p>\u67ef\u91cc\u5316\u53ef\u4ee5\u5e2e\u52a9\u63d0\u9ad8\u6570\u7ec4\u6620\u5c04\u64cd\u4f5c\u7684\u6027\u80fd\uff0c\u56e0\u4e3a\u6bcf\u6b21\u6620\u5c04\u64cd\u4f5c\u4e0d\u9700\u8981\u91cd\u65b0\u521b\u5efa\u6620\u5c04\u51fd\u6570\u3002\u901a\u8fc7\u67ef\u91cc\u5316\u521b\u5efa\u53ef\u91cd\u590d\u4f7f\u7528\u7684\u6620\u5c04\u51fd\u6570\uff0c\u53ef\u4ee5\u51cf\u5c11\u51fd\u6570 overhead \u5e76\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<pre>$map = curry(function ($fn, $arr) { return array_map($fn, $arr); });\n$mappedArray = $map('strtoupper')(['foo', 'bar', 'baz']);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u51fd\u6570\u8bbe\u8ba1\u6a21\u5f0f\u5728 PHP \u4e2d\u53d1\u6325\u7740\u81f3\u5173\u91cd\u8981\u7684\u4f5c\u7528\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u53ef\u7ef4\u62a4\u6027\u3001\u7075\u6d3b\u6027\u548c\u6027\u80fd\u3002\u901a\u8fc7\u7406\u89e3\u548c\u5e94\u7528\u94fe\u5f0f\u6a21\u5f0f\u3001\u67ef\u91cc\u5316\u548c\u5907\u5fd8\u5f55\u6a21\u5f0f\u7b49\u6a21\u5f0f\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u663e\u8457\u4f18\u5316\u5176\u4ee3\u7801\u5e76\u5728 PHP \u5e94\u7528\u7a0b\u5e8f\u4e2d\u83b7\u5f97\u66f4\u597d\u7684\u6027\u80fd\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fPHP \u51fd\u6570\u8bbe\u8ba1\u6a21\u5f0f\u5e94\u7528\u4e0e\u6027\u80fd\u4f18\u5316\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u8bbe\u8ba1\u6a21\u5f0f\u5e94\u7528\u4e0e\u6027\u80fd\u4f18\u5316 \u51fd\u6570\u8bbe\u8ba1\u6a21\u5f0f\u662f\u4e00\u79cd\u5c06\u51fd\u6570\u7ec4\u7ec7\u6210\u4e0d\u540c\u6a21\u5f0f\u7684\u5b9e\u8df5\uff0c\u65e8\u5728\u63d0\u9ad8\u4ee3\u7801\u53ef\u7ef4\u62a4\u6027\u3001\u7075\u6d3b\u6027\u548c\u6027\u80fd\u3002\u672c\u6587\u5c06\u63a2\u8ba8 PHP \u4e2d\u5e38\u89c1\u7684\u51fd\u6570\u8bbe\u8ba1\u6a21\u5f0f\u53ca\u5176\u5982\u4f55\u5e94\u7528\u4e8e\u4f18\u5316\u4ee3\u7801\u6027\u80fd\u3002 \u51fd\u6570\u94fe\u5f0f\u6a21\u5f0f \u94fe\u5f0f\u6a21\u5f0f\u5141\u8bb8\u60a8\u5c06\u4e00\u8fde\u4e32\u51fd\u6570\u5e94\u7528\u4e8e\u540c\u4e00\u8f93\u5165\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u8fde\u63a5\u51fd\u6570\u8fd4\u56de\u7684\u503c\u4e0e subsequent \u51fd\u6570\u7684\u8f93\u5165\u6765\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u94fe\u5f0f\u6a21\u5f0f\u5c06\u591a\u4e2a\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570\u5e94\u7528\u4e8e\u4e00\u4e2a\u5b57\u7b26\u4e32\uff1a \u7acb\u5373\u5b66\u4e60\u201cPHP\u514d\u8d39\u5b66\u4e60\u7b14\u8bb0\uff08\u6df1\u5165\uff09\u201d\uff1b $processedString = strtoupper($string) -&amp;gt;replace(&#8216; &#8216;, &#8216;-&#8216;) -&amp;gt;substr(0, 10); \u767b\u5f55\u540e\u590d\u5236 \u67ef\u91cc\u5316 \u67ef\u91cc\u5316\u662f\u4e00\u79cd\u5c06\u591a\u53c2\u6570\u51fd\u6570\u8f6c\u6362\u4e3a\u4e00\u5e8f\u5217\u63a5\u53d7\u5355\u4e2a\u53c2\u6570\u7684\u51fd\u6570\u7684\u6280\u672f\u3002\u8fd9\u6709\u52a9\u4e8e\u63d0\u9ad8\u7075\u6d3b\u6027\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u60a8\u90e8\u5206\u5e94\u7528\u51fd\u6570\u5e76\u7a0d\u540e\u63d0\u4f9b\u5176\u4f59\u53c2\u6570\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u53ef\u4ee5\u4f7f\u7528\u67ef\u91cc\u5316\u521b\u5efa\u53ef\u91cd\u590d\u4f7f\u7528\u7684\u51fd\u6570\uff0c\u5982\u6570\u7ec4\u6620\u5c04\uff1a $map = curry(function ($fn, $arr) { return array_map($fn, $arr); }); $mappedArray = $map(&#8216;strtoupper&#8217;)([&#8216;foo&#8217;, &#8216;bar&#8217;, &#8216;baz&#8217;]); \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 \u5907\u5fd8\u5f55\u6a21\u5f0f \u5907\u5fd8\u5f55\u6a21\u5f0f\u901a\u8fc7\u7f13\u5b58\u51fd\u6570\u7ed3\u679c\u6765\u63d0\u9ad8\u6027\u80fd\u3002\u8fd9\u5bf9\u4e8e\u4ee3\u4ef7\u6602\u8d35\u6216\u8ba1\u7b97\u5bc6\u96c6\u578b\u7684\u51fd\u6570\u5c24\u5176\u6709\u7528\u3002\u8981\u5b9e\u73b0\u5907\u5fd8\u5f55\u6a21\u5f0f\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u68c0\u67e5\u7f13\u5b58\u5e76\u53ea\u6709\u5728\u7f13\u5b58\u65e0\u6548\u65f6\u624d\u8ba1\u7b97\u7ed3\u679c\u3002 function fibonacci($n) { static $memo = []; if (!isset($memo[$n])) { $memo[$n] = $n &lt;p&gt;&lt;strong&gt;\u5b9e\u6218\u6848\u4f8b&lt;\/strong&gt;&lt;\/p&gt;&lt;p&gt;&lt;strong&gt;\u6848\u4f8b 1\uff1a\u4f18\u5316\u5b57\u7b26\u4e32\u5904\u7406&lt;\/strong&gt;&lt;\/p&gt;&lt;p&gt;\u4f7f\u7528\u94fe\u5f0f\u6a21\u5f0f\u53ef\u4ee5\u4f18\u5316\u5b57\u7b26\u4e32\u5904\u7406\u4efb\u52a1\uff0c\u51cf\u5c11\u51fd\u6570\u8c03\u7528\u6570\u91cf\u5e76\u63d0\u9ad8\u53ef\u8bfb\u6027\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c06\u591a\u4e2a\u5b57\u7b26\u4e32\u5904\u7406\u51fd\u6570\u94fe\u5f0f\u5316\u6765\u521b\u5efa\u53ef\u91cd\u590d\u4f7f\u7528\u7684\u5b57\u7b26\u4e32\u6e05\u7406\u5de5\u5177\u3002&lt;\/p&gt;&lt;pre [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-777","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/777","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=777"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/777\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=777"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=777"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=777"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}