{"id":47774,"date":"2024-12-02T17:53:13","date_gmt":"2024-12-02T09:53:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47774\/"},"modified":"2024-12-02T17:53:13","modified_gmt":"2024-12-02T09:53:13","slug":"php-%e5%87%bd%e6%95%b0%e4%b8%ad%e5%bc%95%e7%94%a8%e4%bc%a0%e9%80%92%e7%9a%84%e9%99%b7%e9%98%b1","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47774\/","title":{"rendered":"PHP \u51fd\u6570\u4e2d\u5f15\u7528\u4f20\u9012\u7684\u9677\u9631"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u4e2d\u5f15\u7528\u4f20\u9012\u7684\u9677\u9631<\/h1>\n<p>IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300aPHP \u51fd\u6570\u4e2d\u5f15\u7528\u4f20\u9012\u7684\u9677\u9631\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p>\u5f15\u7528\u4f20\u9012\u5728 PHP \u4e2d\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u539f\u59cb\u53d8\u91cf\uff0c\u4f46\u5b58\u5728\u9677\u9631\uff1a\u610f\u5916\u4fee\u6539\u3001\u526f\u4f5c\u7528\u3001\u751f\u547d\u5468\u671f\u95ee\u9898\u3002\u907f\u514d\u9677\u9631\u7684\u65b9\u6cd5\u6709\uff1a\u8c28\u614e\u4f7f\u7528\u3001\u660e\u786e\u6587\u6863\u3001\u4f7f\u7528\u5c40\u90e8\u53d8\u91cf\u5e76\u9500\u6bc1\u53c2\u6570\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729935331671cb7e30f159.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u4e2d\u5f15\u7528\u4f20\u9012\u7684\u9677\u9631\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u4e2d\u5f15\u7528\u4f20\u9012\u7684\u9677\u9631\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u4e2d\u5f15\u7528\u4f20\u9012\u7684\u9677\u9631<\/strong><\/p>\n<p>PHP \u4e2d\u7684\u53c2\u6570\u4f20\u9012\u91c7\u7528\u4e24\u79cd\u673a\u5236\uff1a\u6309\u503c\u4f20\u9012\u548c\u6309\u5f15\u7528\u4f20\u9012\u3002\u6309\u5f15\u7528\u4f20\u9012\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u53d8\u91cf\u7684\u539f\u59cb\u503c\uff0c\u800c\u6309\u503c\u4f20\u9012\u5219\u53ea\u4f1a\u521b\u5efa\u53d8\u91cf\u7684\u4e00\u4e2a\u526f\u672c\u8fdb\u884c\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u5f15\u7528\u4f20\u9012<\/strong><\/p>\n<p>\u4f7f\u7528 &#8220;&amp;&#8221; \u7b26\u53f7\u53ef\u4ee5\u5b9e\u73b0\u5f15\u7528\u4f20\u9012\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>function swap(&amp;$a, &amp;$b) {\n  $temp = $a;\n  $a = $b;\n  $b = $temp;\n}<\/pre>\n<p>\u8c03\u7528\u8be5\u51fd\u6570\u65f6\uff0c\u53d8\u91cf\u4ee5\u5f15\u7528\u65b9\u5f0f\u4f20\u9012\uff0c\u8fd9\u610f\u5473\u7740\u51fd\u6570\u4e2d\u7684\u4efb\u4f55\u4fee\u6539\u90fd\u4f1a\u53cd\u6620\u5230\u539f\u59cb\u53d8\u91cf\u4e0a\uff1a<\/p>\n<pre>$a = 1;\n$b = 2;\nswap($a, $b);\necho $a; \/\/ \u8f93\u51fa 2\necho $b; \/\/ \u8f93\u51fa 1<\/pre>\n<p><strong>\u9677\u9631<\/strong><\/p>\n<p>\u5f15\u7528\u4f20\u9012\u867d\u7136\u80fd\u63d0\u9ad8\u6548\u7387\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4e5f\u4f1a\u5e26\u6765\u9677\u9631\uff1a<\/p>\n<ul>\n<li><strong>\u65e0\u610f\u4fee\u6539\u539f\u59cb\u53d8\u91cf\uff1a<\/strong>\u51fd\u6570\u53ef\u80fd\u610f\u5916\u5730\u4fee\u6539\u4e86\u5916\u90e8\u53d8\u91cf\uff0c\u5bfc\u81f4\u96be\u4ee5\u8c03\u8bd5\u7684\u9519\u8bef\u3002<\/li>\n<li><strong>\u526f\u4f5c\u7528\uff1a<\/strong>\u51fd\u6570\u7684\u5f15\u7528\u4f20\u9012\u53c2\u6570\u53ef\u80fd\u4f1a\u53d7\u5230\u5176\u4ed6\u51fd\u6570\u7684\u5f71\u54cd\uff0c\u5bfc\u81f4\u96be\u4ee5\u9884\u6d4b\u7684\u884c\u4e3a\u3002<\/li>\n<li><strong>\u751f\u547d\u5468\u671f\uff1a<\/strong>\u5f15\u7528\u4f20\u9012\u7684\u53d8\u91cf\u5fc5\u987b\u5728\u51fd\u6570\u6267\u884c\u671f\u95f4\u4fdd\u6301\u6709\u6548\uff0c\u5426\u5219\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5728\u8bba\u575b\u4e2d\u5b9e\u73b0\u7528\u6237\u8bc4\u8bba\u7cfb\u7edf\u65f6\u7684\u5f15\u7528\u4f20\u9012\u9677\u9631\u793a\u4f8b\uff1a<\/p>\n<pre>function saveComment(&amp;$comment, $postId) {\n  $comment['post_id'] = $postId;\n  \/\/ \u63d2\u5165\u6570\u636e\u5e93...\n}\n\n$comment = [];\nsaveComment($comment, 123); \/\/ \u8bc4\u8bba\u88ab\u63d2\u5165\u6570\u636e\u5e93\n\n\/\/ \u540e\u7eed\u4ee3\u7801\nunset($comment);\n\n\/\/ \u8bc4\u8bba\u88ab\u5220\u9664\uff0c\u56e0\u4e3a\u539f\u59cb\u53d8\u91cf\u5df2\u88ab\u9500\u6bc1<\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>saveComment<\/code> \u51fd\u6570\u5c1d\u8bd5\u4fee\u6539 <code>$comment<\/code> \u53d8\u91cf\uff0c\u4f46\u7531\u4e8e\u8be5\u53d8\u91cf\u5728\u51fd\u6570\u6267\u884c\u540e\u88ab\u9500\u6bc1\uff0c\u56e0\u6b64\u4fee\u6539\u672a\u80fd\u751f\u6548\uff0c\u5bfc\u81f4\u8bc4\u8bba\u5728\u6570\u636e\u5e93\u4e2d\u88ab\u5220\u9664\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u907f\u514d\u5f15\u7528\u4f20\u9012\u9677\u9631\u7684\u65b9\u6cd5\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u8c28\u614e\u4f7f\u7528\u5f15\u7528\u4f20\u9012\uff0c\u4ec5\u5728\u5fc5\u8981\u65f6\u4f7f\u7528\u3002<\/li>\n<li>\u660e\u786e\u6587\u6863\u5f15\u7528\u4f20\u9012\u53c2\u6570\u3002<\/li>\n<li>\u4f7f\u7528\u5c40\u90e8\u53d8\u91cf\u5e76\u5728\u51fd\u6570\u7ed3\u675f\u65f6\u9500\u6bc1\u5f15\u7528\u4f20\u9012\u7684\u53c2\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<p><strong>\u6309\u5f15\u7528\u4f20\u9012\u4e0d\u80fd\u4fee\u6539\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u4f8b\u5982\u6574\u578b\u6216\u5b57\u7b26\u578b\uff0c\u53ea\u80fd\u4fee\u6539\u5bf9\u8c61\u7684\u5c5e\u6027\u6216\u6570\u7ec4\u7684\u503c\u3002<\/strong><\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aPHP \u51fd\u6570\u4e2d\u5f15\u7528\u4f20\u9012\u7684\u9677\u9631\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u7c73\u4e91\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u4e2d\u5f15\u7528\u4f20\u9012\u7684\u9677\u9631 IT\u884c\u4e1a\u76f8\u5bf9\u4e8e\u4e00\u822c\u4f20\u7edf\u884c\u4e1a\uff0c\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u66f4\u5feb\uff0c\u4e00\u65e6\u505c\u6b62\u4e86\u5b66\u4e60\uff0c\u5f88\u5feb\u5c31\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u6240\u4ee5\u6211\u4eec\u9700\u8981\u8e0f\u8e0f\u5b9e\u5b9e\u7684\u4e0d\u65ad\u5b66\u4e60\uff0c\u7cbe\u8fdb\u81ea\u5df1\u7684\u6280\u672f\uff0c\u5c24\u5176\u662f\u521d\u5b66\u8005\u3002\u4eca\u5929\u7c73\u4e91\u7ed9\u5927\u5bb6\u6574\u7406\u4e86\u300aPHP \u51fd\u6570\u4e2d\u5f15\u7528\u4f20\u9012\u7684\u9677\u9631\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01 \u5f15\u7528\u4f20\u9012\u5728 PHP \u4e2d\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u539f\u59cb\u53d8\u91cf\uff0c\u4f46\u5b58\u5728\u9677\u9631\uff1a\u610f\u5916\u4fee\u6539\u3001\u526f\u4f5c\u7528\u3001\u751f\u547d\u5468\u671f\u95ee\u9898\u3002\u907f\u514d\u9677\u9631\u7684\u65b9\u6cd5\u6709\uff1a\u8c28\u614e\u4f7f\u7528\u3001\u660e\u786e\u6587\u6863\u3001\u4f7f\u7528\u5c40\u90e8\u53d8\u91cf\u5e76\u9500\u6bc1\u53c2\u6570\u3002 PHP \u51fd\u6570\u4e2d\u5f15\u7528\u4f20\u9012\u7684\u9677\u9631 PHP \u4e2d\u7684\u53c2\u6570\u4f20\u9012\u91c7\u7528\u4e24\u79cd\u673a\u5236\uff1a\u6309\u503c\u4f20\u9012\u548c\u6309\u5f15\u7528\u4f20\u9012\u3002\u6309\u5f15\u7528\u4f20\u9012\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u53d8\u91cf\u7684\u539f\u59cb\u503c\uff0c\u800c\u6309\u503c\u4f20\u9012\u5219\u53ea\u4f1a\u521b\u5efa\u53d8\u91cf\u7684\u4e00\u4e2a\u526f\u672c\u8fdb\u884c\u64cd\u4f5c\u3002 \u5f15\u7528\u4f20\u9012 \u4f7f\u7528 &#8220;&amp;&#8221; \u7b26\u53f7\u53ef\u4ee5\u5b9e\u73b0\u5f15\u7528\u4f20\u9012\u3002\u4f8b\u5982\uff1a function swap(&amp;$a, &amp;$b) { $temp = $a; $a = $b; $b = $temp; } \u8c03\u7528\u8be5\u51fd\u6570\u65f6\uff0c\u53d8\u91cf\u4ee5\u5f15\u7528\u65b9\u5f0f\u4f20\u9012\uff0c\u8fd9\u610f\u5473\u7740\u51fd\u6570\u4e2d\u7684\u4efb\u4f55\u4fee\u6539\u90fd\u4f1a\u53cd\u6620\u5230\u539f\u59cb\u53d8\u91cf\u4e0a\uff1a $a = 1; $b = 2; swap($a, $b); echo $a; \/\/ \u8f93\u51fa 2 echo $b; \/\/ \u8f93\u51fa 1 \u9677\u9631 \u5f15\u7528\u4f20\u9012\u867d\u7136\u80fd\u63d0\u9ad8\u6548\u7387\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4e5f\u4f1a\u5e26\u6765\u9677\u9631\uff1a \u65e0\u610f\u4fee\u6539\u539f\u59cb\u53d8\u91cf\uff1a\u51fd\u6570\u53ef\u80fd\u610f\u5916\u5730\u4fee\u6539\u4e86\u5916\u90e8\u53d8\u91cf\uff0c\u5bfc\u81f4\u96be\u4ee5\u8c03\u8bd5\u7684\u9519\u8bef\u3002 \u526f\u4f5c\u7528\uff1a\u51fd\u6570\u7684\u5f15\u7528\u4f20\u9012\u53c2\u6570\u53ef\u80fd\u4f1a\u53d7\u5230\u5176\u4ed6\u51fd\u6570\u7684\u5f71\u54cd\uff0c\u5bfc\u81f4\u96be\u4ee5\u9884\u6d4b\u7684\u884c\u4e3a\u3002 \u751f\u547d\u5468\u671f\uff1a\u5f15\u7528\u4f20\u9012\u7684\u53d8\u91cf\u5fc5\u987b\u5728\u51fd\u6570\u6267\u884c\u671f\u95f4\u4fdd\u6301\u6709\u6548\uff0c\u5426\u5219\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002 \u5b9e\u6218\u6848\u4f8b \u4ee5\u4e0b\u662f\u4e00\u4e2a\u5728\u8bba\u575b\u4e2d\u5b9e\u73b0\u7528\u6237\u8bc4\u8bba\u7cfb\u7edf\u65f6\u7684\u5f15\u7528\u4f20\u9012\u9677\u9631\u793a\u4f8b\uff1a [&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-47774","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47774","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=47774"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47774\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47774"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47774"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47774"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}