{"id":47603,"date":"2024-12-02T17:28:50","date_gmt":"2024-12-02T09:28:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47603\/"},"modified":"2024-12-02T17:28:50","modified_gmt":"2024-12-02T09:28:50","slug":"php-%e5%87%bd%e6%95%b0%e4%b8%ad%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e5%bc%95%e7%94%a8%ef%bc%9a%e7%90%86%e8%a7%a3%e5%bc%95%e7%94%a8%e7%94%9f%e5%91%bd%e5%91%a8%e6%9c%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47603\/","title":{"rendered":"PHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u751f\u547d\u5468\u671f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u751f\u547d\u5468\u671f<\/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\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u751f\u547d\u5468\u671f\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01<\/p>\n<p>PHP \u51fd\u6570\u4e2d\uff0c\u4f7f\u7528\u5f15\u7528\u7b26\u53f7 (&amp;) \u58f0\u660e\u5f15\u7528\u53c2\u6570\uff0c\u5141\u8bb8\u51fd\u6570\u76f4\u63a5\u4fee\u6539\u53d8\u91cf\u503c\uff0c\u800c\u4e0d\u662f\u521b\u5efa\u526f\u672c\u3002\u901a\u8fc7\u5f15\u7528\u4fee\u6539\u53d8\u91cf\u53ef\u4f18\u5316\u4ee3\u7801\u5e76\u907f\u514d\u610f\u5916\u526f\u4f5c\u7528\uff0c\u4f46\u8981\u6ce8\u610f\u5f15\u7528\u53d8\u91cf\u4ec5\u5728\u51fd\u6570\u6267\u884c\u671f\u95f4\u6709\u6548\uff0c\u4f20\u9012\u7684\u53d8\u91cf\u5fc5\u987b\u6709\u6548\u4e14\u4f7f\u7528\u65f6\u9700\u8c28\u614e\uff0c\u5c24\u5176\u662f\u5d4c\u5957\u51fd\u6570\u8c03\u7528\u65f6\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729925429671c913539c8a.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u751f\u547d\u5468\u671f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u751f\u547d\u5468\u671f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u751f\u547d\u5468\u671f<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>\u5f15\u7528\u5141\u8bb8\u51fd\u6570\u76f4\u63a5\u4fee\u6539\u53d8\u91cf\uff0c\u800c\u4e0d\u662f\u521b\u5efa\u5176\u526f\u672c\u3002\u4e86\u89e3\u5982\u4f55\u4f7f\u7528\u5f15\u7528\u5bf9\u4e8e\u4f18\u5316\u4ee3\u7801\u548c\u907f\u514d\u610f\u5916\u526f\u4f5c\u7528\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p><strong>\u58f0\u660e\u5f15\u7528<\/strong><\/p>\n<p>\u4f7f\u7528 <code>&amp;<\/code> \u7b26\u53f7\u5728\u51fd\u6570\u53c2\u6570\u524d\u58f0\u660e\u5f15\u7528\uff1a<\/p>\n<pre>function modifyByReference(&amp;$var) {\n  \/\/ \u64cd\u4f5c $var \u5c06\u76f4\u63a5\u4fee\u6539\u539f\u59cb\u53d8\u91cf\n}<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b\uff1a\u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u7684\u503c<\/strong><\/p>\n<pre>function swapByReference(&amp;$a, &amp;$b) {\n  $temp = $a;\n  $a = $b;\n  $b = $temp;\n}\n\n$a = 1;\n$b = 2;\n\nswapByReference($a, $b);\n\n\/\/ $a \u73b0\u5728\u4e3a 2\uff0c$b \u4e3a 1<\/pre>\n<p><strong>\u5f15\u7528\u751f\u547d\u5468\u671f<\/strong><\/p>\n<p>\u51fd\u6570\u4e2d\u7684\u5f15\u7528\u53d8\u91cf\u4ec5\u5728\u51fd\u6570\u6267\u884c\u671f\u95f4\u6709\u6548\uff1a<\/p>\n<pre>function modifyByReference(&amp;$var) {\n  $var = 'new value';\n}\n\n$var = 'original value';\nmodifyByReference($var);\n\n\/\/ $var \u4ecd\u7136\u662f 'original value'\uff0c\u56e0\u4e3a\u51fd\u6570\u4e2d\u7684\u5f15\u7528\u4ec5\u5728\u51fd\u6570\u6267\u884c\u671f\u95f4\u6709\u6548<\/pre>\n<p><strong>\u4f7f\u7528\u5f15\u7528\u7684\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u53c2\u6570\u4f20\u9012\u7684\u662f\u6709\u6548\u7684\u5f15\u7528\uff0c\u800c\u4e0d\u662f\u672a\u5b9a\u4e49\u7684\u53d8\u91cf\u3002<\/li>\n<li>\u8c28\u614e\u4f7f\u7528\u5f15\u7528\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ef\u4ee5\u5bfc\u81f4\u610f\u5916\u7684\u884c\u4e3a\uff0c\u5c24\u5176\u662f\u5728\u5d4c\u5957\u51fd\u6570\u8c03\u7528\u4e2d\u3002<\/li>\n<li>\u5728\u9700\u8981\u4f20\u9012\u5927\u91cf\u6570\u636e\u65f6\uff0c\u8003\u8651\u4f7f\u7528\u5f15\u7528\u6570\u7ec4\u6216\u5bf9\u8c61\uff0c\u800c\u4e0d\u662f\u5177\u6709\u5355\u4e2a\u5f15\u7528\u53c2\u6570\u7684\u5927\u91cf\u51fd\u6570\u3002<\/li>\n<\/ul>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aPHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u751f\u547d\u5468\u671f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u7c73\u4e91\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u751f\u547d\u5468\u671f 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\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u751f\u547d\u5468\u671f\u300b\uff0c\u804a\u804a\uff0c\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff01 PHP \u51fd\u6570\u4e2d\uff0c\u4f7f\u7528\u5f15\u7528\u7b26\u53f7 (&amp;) \u58f0\u660e\u5f15\u7528\u53c2\u6570\uff0c\u5141\u8bb8\u51fd\u6570\u76f4\u63a5\u4fee\u6539\u53d8\u91cf\u503c\uff0c\u800c\u4e0d\u662f\u521b\u5efa\u526f\u672c\u3002\u901a\u8fc7\u5f15\u7528\u4fee\u6539\u53d8\u91cf\u53ef\u4f18\u5316\u4ee3\u7801\u5e76\u907f\u514d\u610f\u5916\u526f\u4f5c\u7528\uff0c\u4f46\u8981\u6ce8\u610f\u5f15\u7528\u53d8\u91cf\u4ec5\u5728\u51fd\u6570\u6267\u884c\u671f\u95f4\u6709\u6548\uff0c\u4f20\u9012\u7684\u53d8\u91cf\u5fc5\u987b\u6709\u6548\u4e14\u4f7f\u7528\u65f6\u9700\u8c28\u614e\uff0c\u5c24\u5176\u662f\u5d4c\u5957\u51fd\u6570\u8c03\u7528\u65f6\u3002 PHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u751f\u547d\u5468\u671f \u7b80\u4ecb \u5f15\u7528\u5141\u8bb8\u51fd\u6570\u76f4\u63a5\u4fee\u6539\u53d8\u91cf\uff0c\u800c\u4e0d\u662f\u521b\u5efa\u5176\u526f\u672c\u3002\u4e86\u89e3\u5982\u4f55\u4f7f\u7528\u5f15\u7528\u5bf9\u4e8e\u4f18\u5316\u4ee3\u7801\u548c\u907f\u514d\u610f\u5916\u526f\u4f5c\u7528\u81f3\u5173\u91cd\u8981\u3002 \u58f0\u660e\u5f15\u7528 \u4f7f\u7528 &amp; \u7b26\u53f7\u5728\u51fd\u6570\u53c2\u6570\u524d\u58f0\u660e\u5f15\u7528\uff1a function modifyByReference(&amp;$var) { \/\/ \u64cd\u4f5c $var \u5c06\u76f4\u63a5\u4fee\u6539\u539f\u59cb\u53d8\u91cf } \u5b9e\u6218\u6848\u4f8b\uff1a\u4ea4\u6362\u4e24\u4e2a\u53d8\u91cf\u7684\u503c function swapByReference(&amp;$a, &amp;$b) { $temp = $a; $a = $b; $b = $temp; } $a = 1; $b = 2; swapByReference($a, $b); \/\/ $a \u73b0\u5728\u4e3a 2\uff0c$b \u4e3a 1 \u5f15\u7528\u751f\u547d\u5468\u671f \u51fd\u6570\u4e2d\u7684\u5f15\u7528\u53d8\u91cf\u4ec5\u5728\u51fd\u6570\u6267\u884c\u671f\u95f4\u6709\u6548\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-47603","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47603","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=47603"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47603\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}