{"id":47599,"date":"2024-12-02T14:27:40","date_gmt":"2024-12-02T06:27:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47599\/"},"modified":"2024-12-02T14:27:40","modified_gmt":"2024-12-02T06:27:40","slug":"php-%e5%87%bd%e6%95%b0%e4%b8%ad%e8%af%a5%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e5%bc%95%e7%94%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47599\/","title":{"rendered":"PHP \u51fd\u6570\u4e2d\u8be5\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u4e2d\u8be5\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1f<\/h1>\n<p>\u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u4e2d\u8be5\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1f\u300b<\/span>\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01<\/p>\n<p>\u5f15\u7528\u53c2\u6570\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u4f20\u9012\u53d8\u91cf\u7684\u503c\uff0c\u65e0\u9700\u590d\u5236\u53d8\u91cf\uff0c\u63d0\u9ad8\u6027\u80fd\u3002\u8bed\u6cd5\uff1a\u51fd\u6570\u7b7e\u540d\u4e2d\u7528 &#8220;&amp;&#8221; \u6307\u5b9a\u5f15\u7528\uff0c\u8c03\u7528\u65f6\u7528 &#8220;&amp;&#8221; \u4f20\u9012\u53d8\u91cf\u3002\u5b9e\u6218\uff1a\u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u503c\u800c\u4e0d\u4f7f\u7528\u4e34\u65f6\u53d8\u91cf\u7684\u51fd\u6570\u3002\u6ce8\u610f\u4e8b\u9879\uff1a\u53ea\u80fd\u4f20\u9012\u53d8\u91cf\u4f5c\u4e3a\u5f15\u7528\uff0c\u4fee\u6539\u5f15\u7528\u53c2\u6570\u7684\u503c\u4f1a\u5f71\u54cd\u4f20\u9012\u53d8\u91cf\uff0cPHP \u4f1a\u590d\u5236\u5f15\u7528\u53c2\u6570\u7684\u5185\u5bb9\u800c\u4e0d\u662f\u5f15\u7528\uff0c\u5185\u90e8\u4fee\u6539\u53ea\u5f71\u54cd\u526f\u672c\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729925310671c90be6dc45.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u4e2d\u8be5\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u4e2d\u8be5\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u4e2d\u5f15\u7528\u53c2\u6570\u7684\u7528\u6cd5<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u5f15\u7528\u53c2\u6570\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u4f20\u9012\u7ed9\u5b83\u7684\u53d8\u91cf\u7684\u503c\uff0c\u800c\u65e0\u9700\u590d\u5236\u53d8\u91cf\u3002\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u65f6\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<p>\u5728\u51fd\u6570\u7b7e\u540d\u4e2d\uff0c\u4f7f\u7528 <code>&amp;<\/code> \u7b26\u53f7\u5c06\u53c2\u6570\u6307\u5b9a\u4e3a\u5f15\u7528\u53c2\u6570\u3002<\/p>\n<pre>function foo(&amp;$bar) {\n  \/\/ ...\n}<\/pre>\n<p>\u5f53\u51fd\u6570\u88ab\u8c03\u7528\u65f6\uff0c\u4f7f\u7528 <code>&amp;<\/code> \u7b26\u53f7\u4f20\u9012\u53d8\u91cf\u3002<\/p>\n<pre>$bar = 10;\nfoo($bar);<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u503c\u800c\u4e0d\u4f7f\u7528\u4e34\u65f6\u53d8\u91cf\u7684\u51fd\u6570\uff1a<\/p>\n<pre>&lt;?php\n\nfunction swap(&amp;$a, &amp;$b) {\n  $temp = $a;\n  $a = $b;\n  $b = $temp;\n}\n\n$a = 1;\n$b = 2;\n\necho \"Before swap: a = $a, b = $b\\n\";\n\nswap($a, $b);\n\necho \"After swap: a = $a, b = $b\\n\";\n\n?&gt;<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Before swap: a = 1, b = 2\nAfter swap: a = 2, b = 1<\/pre>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u53ea\u80fd\u5c06\u53d8\u91cf\u4f5c\u4e3a\u5f15\u7528\u4f20\u9012\u3002\u5e38\u91cf\u3001\u6570\u7ec4\u548c\u5bf9\u8c61\u4e0d\u80fd\u4f5c\u4e3a\u5f15\u7528\u4f20\u9012\u3002<\/li>\n<li>\u5728\u51fd\u6570\u5185\u90e8\u4fee\u6539\u5f15\u7528\u53c2\u6570\u7684\u503c\u4f1a\u5f71\u54cd\u4f20\u9012\u8be5\u53c2\u6570\u7684\u53d8\u91cf\u3002<\/li>\n<li>\u5bf9\u4e8e\u5f15\u7528\u53c2\u6570\uff0cPHP \u4f1a\u590d\u5236\u8be5\u53d8\u91cf\u7684\u5185\u5bb9\uff0c\u800c\u4e0d\u662f\u5f15\u7528\u3002\u56e0\u6b64\uff0c\u5728\u51fd\u6570\u5185\u90e8\u8fdb\u884c\u4fee\u6539\u53ea\u4f1a\u5f71\u54cd\u526f\u672c\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u539f\u59cb\u53d8\u91cf\u3002<\/li>\n<\/ul>\n<p>\u5230\u8fd9\u91cc\uff0c\u6211\u4eec\u4e5f\u5c31\u8bb2\u5b8c\u4e86\u300aPHP \u51fd\u6570\u4e2d\u8be5\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1f\u300b\u7684\u5185\u5bb9\u4e86\u3002\u4e2a\u4eba\u8ba4\u4e3a\uff0c\u57fa\u7840\u77e5\u8bc6\u7684\u5b66\u4e60\u548c\u5de9\u56fa\uff0c\u662f\u4e3a\u4e86\u66f4\u597d\u7684\u5c06\u5176\u8fd0\u7528\u5230\u9879\u76ee\u4e2d\uff0c\u6b22\u8fce\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u5e26\u4f60\u4e86\u89e3\u66f4\u591a\u5173\u4e8ephp,\u5f15\u7528\u7684\u77e5\u8bc6\u70b9\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u4e2d\u8be5\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1f \u54c8\u55bd\uff01\u4eca\u5929\u5fc3\u8840\u6765\u6f6e\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86\u300aPHP \u51fd\u6570\u4e2d\u8be5\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1f\u300b\uff0c\u60f3\u5fc5\u5927\u5bb6\u5e94\u8be5\u5bf9\u6587\u7ae0\u90fd\u4e0d\u964c\u751f\u5427\uff0c\u90a3\u4e48\u9605\u8bfb\u672c\u6587\u5c31\u90fd\u4e0d\u4f1a\u5f88\u56f0\u96be\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u82e5\u662f\u4f60\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u5343\u4e07\u522b\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0~\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60\uff01 \u5f15\u7528\u53c2\u6570\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u4f20\u9012\u53d8\u91cf\u7684\u503c\uff0c\u65e0\u9700\u590d\u5236\u53d8\u91cf\uff0c\u63d0\u9ad8\u6027\u80fd\u3002\u8bed\u6cd5\uff1a\u51fd\u6570\u7b7e\u540d\u4e2d\u7528 &#8220;&amp;&#8221; \u6307\u5b9a\u5f15\u7528\uff0c\u8c03\u7528\u65f6\u7528 &#8220;&amp;&#8221; \u4f20\u9012\u53d8\u91cf\u3002\u5b9e\u6218\uff1a\u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u503c\u800c\u4e0d\u4f7f\u7528\u4e34\u65f6\u53d8\u91cf\u7684\u51fd\u6570\u3002\u6ce8\u610f\u4e8b\u9879\uff1a\u53ea\u80fd\u4f20\u9012\u53d8\u91cf\u4f5c\u4e3a\u5f15\u7528\uff0c\u4fee\u6539\u5f15\u7528\u53c2\u6570\u7684\u503c\u4f1a\u5f71\u54cd\u4f20\u9012\u53d8\u91cf\uff0cPHP \u4f1a\u590d\u5236\u5f15\u7528\u53c2\u6570\u7684\u5185\u5bb9\u800c\u4e0d\u662f\u5f15\u7528\uff0c\u5185\u90e8\u4fee\u6539\u53ea\u5f71\u54cd\u526f\u672c\u3002 PHP \u51fd\u6570\u4e2d\u5f15\u7528\u53c2\u6570\u7684\u7528\u6cd5 \u7b80\u4ecb \u5f15\u7528\u53c2\u6570\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u4f20\u9012\u7ed9\u5b83\u7684\u53d8\u91cf\u7684\u503c\uff0c\u800c\u65e0\u9700\u590d\u5236\u53d8\u91cf\u3002\u8fd9\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u65f6\u3002 \u8bed\u6cd5 \u5728\u51fd\u6570\u7b7e\u540d\u4e2d\uff0c\u4f7f\u7528 &amp; \u7b26\u53f7\u5c06\u53c2\u6570\u6307\u5b9a\u4e3a\u5f15\u7528\u53c2\u6570\u3002 function foo(&amp;$bar) { \/\/ &#8230; } \u5f53\u51fd\u6570\u88ab\u8c03\u7528\u65f6\uff0c\u4f7f\u7528 &amp; \u7b26\u53f7\u4f20\u9012\u53d8\u91cf\u3002 $bar = 10; foo($bar); \u5b9e\u6218\u6848\u4f8b \u521b\u5efa\u4e00\u4e2a\u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u503c\u800c\u4e0d\u4f7f\u7528\u4e34\u65f6\u53d8\u91cf\u7684\u51fd\u6570\uff1a &lt;?php function swap(&amp;$a, &amp;$b) { $temp = $a; $a = $b; $b = $temp; } $a = 1; $b = 2; echo [&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-47599","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47599","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=47599"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47599\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}