{"id":47278,"date":"2024-12-02T11:10:25","date_gmt":"2024-12-02T03:10:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47278\/"},"modified":"2024-12-02T11:10:25","modified_gmt":"2024-12-02T03:10:25","slug":"php-%e5%bc%95%e7%94%a8%e4%bc%a0%e9%80%92%ef%bc%9a%e6%8f%ad%e5%bc%80%e5%87%bd%e6%95%b0%e5%8f%82%e6%95%b0%e4%bc%a0%e9%80%92%e6%9c%ba%e5%88%b6%e7%9a%84%e7%a5%9e%e7%a7%98%e9%9d%a2%e7%ba%b1","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47278\/","title":{"rendered":"PHP \u5f15\u7528\u4f20\u9012\uff1a\u63ed\u5f00\u51fd\u6570\u53c2\u6570\u4f20\u9012\u673a\u5236\u7684\u795e\u79d8\u9762\u7eb1"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u5f15\u7528\u4f20\u9012\uff1a\u63ed\u5f00\u51fd\u6570\u53c2\u6570\u4f20\u9012\u673a\u5236\u7684\u795e\u79d8\u9762\u7eb1<\/h1>\n<p>\u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aPHP \u5f15\u7528\u4f20\u9012\uff1a\u63ed\u5f00\u51fd\u6570\u53c2\u6570\u4f20\u9012\u673a\u5236\u7684\u795e\u79d8\u9762\u7eb1\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b<\/p>\n<p>PHP \u63d0\u4f9b\u503c\u4f20\u9012\u548c\u5f15\u7528\u4f20\u9012\u4e24\u79cd\u53c2\u6570\u4f20\u9012\u673a\u5236\u3002\u5f15\u7528\u4f20\u9012\u4f7f\u7528 &amp; \u7b26\u53f7\u5c06\u53c2\u6570\u7684\u5185\u5b58\u5730\u5740\u4f20\u9012\u7ed9\u51fd\u6570\uff0c\u4ece\u800c\u53ef\u4ee5\u4fee\u6539\u539f\u59cb\u53d8\u91cf\u3002\u5f15\u7528\u4f20\u9012\u9002\u7528\u4e8e\u4fee\u6539\u4f20\u9012\u7684\u53c2\u6570\u6216\u63d0\u9ad8\u6027\u80fd\uff08\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u7ed3\u6784\uff09\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729908445671c4edd5d813.jpg\" class=\"aligncenter\" title=\"PHP \u5f15\u7528\u4f20\u9012\uff1a\u63ed\u5f00\u51fd\u6570\u53c2\u6570\u4f20\u9012\u673a\u5236\u7684\u795e\u79d8\u9762\u7eb1\u63d2\u56fe\" alt=\"PHP \u5f15\u7528\u4f20\u9012\uff1a\u63ed\u5f00\u51fd\u6570\u53c2\u6570\u4f20\u9012\u673a\u5236\u7684\u795e\u79d8\u9762\u7eb1\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u5f15\u7528\u4f20\u9012\uff1a\u6df1\u5165\u7406\u89e3\u51fd\u6570\u53c2\u6570\u4f20\u9012\u673a\u5236<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>PHP \u4e2d\u6709\u4e24\u79cd\u51fd\u6570\u53c2\u6570\u4f20\u9012\u673a\u5236\uff1a\u503c\u4f20\u9012\u548c\u5f15\u7528\u4f20\u9012\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u53c2\u6570\u90fd\u88ab\u6309\u503c\u4f20\u9012\u3002\u503c\u4f20\u9012\u7b80\u5355\u5730\u5c06\u53c2\u6570\u7684\u4e00\u4e2a\u526f\u672c\u4f20\u9012\u7ed9\u51fd\u6570\uff0c\u800c\u5f15\u7528\u4f20\u9012\u5219\u5c06\u53c2\u6570\u7684\u539f\u59cb\u5185\u5b58\u5730\u5740\u4f20\u9012\u7ed9\u51fd\u6570\u3002<\/p>\n<p><strong>\u5f15\u7528\u4f20\u9012\u8bed\u6cd5<\/strong><\/p>\n<p>\u8981\u5c06\u53c2\u6570\u4f5c\u4e3a\u5f15\u7528\u4f20\u9012\uff0c\u8bf7\u4f7f\u7528\u7b26\u53f7 <code>&amp;<\/code> \u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\u524d\u7f00\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>function foo(&amp;$param) {\n    \/\/ \u5bf9 $param \u8fdb\u884c\u64cd\u4f5c\uff0c\u8fd9\u5c06\u5f71\u54cd\u539f\u59cb\u53d8\u91cf\n}<\/pre>\n<p><strong>\u4f55\u65f6\u4f7f\u7528\u5f15\u7528\u4f20\u9012\uff1f<\/strong><\/p>\n<p>\u5f15\u7528\u4f20\u9012\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\u5f88\u6709\u7528\uff1a<\/p>\n<ul>\n<li>\u4fee\u6539\u4f20\u9012\u7ed9\u51fd\u6570\u7684\u53c2\u6570<\/li>\n<li>\u901a\u8fc7\u8282\u7701\u5185\u5b58\u6765\u63d0\u9ad8\u6027\u80fd\uff08\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u7ed3\u6784\uff09<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u6848\u4f8b 1\uff1a\u4fee\u6539\u4f20\u9012\u7684\u53c2\u6570<\/strong><\/p>\n<pre>$arr = [1, 2, 3];\n\nfunction modifyArray(&amp;$arr) {\n    $arr[0] = 10;\n}\n\nmodifyArray($arr);\n\necho implode(\", \", $arr); \/\/ \u8f93\u51fa\uff1a10, 2, 3<\/pre>\n<p><strong>\u6848\u4f8b 2\uff1a\u63d0\u9ad8\u6027\u80fd<\/strong><\/p>\n<pre>function processData($data) {\n    \/\/ \u5bf9 $data \u8fdb\u884c\u5904\u7406\uff0c\u8fd9\u53ef\u80fd\u4f1a\u6d88\u8017\u5927\u91cf\u5185\u5b58\n}\n\n$data = [\u5927\u91cf\u6570\u636e];\n\n\/\/ \u6309\u503c\u4f20\u9012\u5c06\u590d\u5236\u6574\u4e2a\u6570\u636e\u96c6\uff0c\u800c\u6309\u5f15\u7528\u4f20\u9012\u5219\u53ea\u4f20\u9012\u4e00\u4e2a\u5f15\u7528\nprocessData(&amp;$data);<\/pre>\n<p><strong>\u53c2\u8003<\/strong><\/p>\n<ul>\n<li>[PHP \u624b\u518c\uff1a\u53c2\u6570\u4f20\u9012](https:\/\/www.php.net\/manual\/zh\/language.parameters.pass.php)<\/li>\n<li>[PHP \u4e2d\u7684\u503c\u4f20\u9012\u548c\u5f15\u7528\u4f20\u9012](https:\/\/www.w3resource.com\/php-exercises\/php-variable-exercise-2.php)<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\u7c73\u4e91\uff01\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u5f15\u7528\u4f20\u9012\uff1a\u63ed\u5f00\u51fd\u6570\u53c2\u6570\u4f20\u9012\u673a\u5236\u7684\u795e\u79d8\u9762\u7eb1 \u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u7c73\u4e91\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300aPHP \u5f15\u7528\u4f20\u9012\uff1a\u63ed\u5f00\u51fd\u6570\u53c2\u6570\u4f20\u9012\u673a\u5236\u7684\u795e\u79d8\u9762\u7eb1\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b PHP \u63d0\u4f9b\u503c\u4f20\u9012\u548c\u5f15\u7528\u4f20\u9012\u4e24\u79cd\u53c2\u6570\u4f20\u9012\u673a\u5236\u3002\u5f15\u7528\u4f20\u9012\u4f7f\u7528 &amp; \u7b26\u53f7\u5c06\u53c2\u6570\u7684\u5185\u5b58\u5730\u5740\u4f20\u9012\u7ed9\u51fd\u6570\uff0c\u4ece\u800c\u53ef\u4ee5\u4fee\u6539\u539f\u59cb\u53d8\u91cf\u3002\u5f15\u7528\u4f20\u9012\u9002\u7528\u4e8e\u4fee\u6539\u4f20\u9012\u7684\u53c2\u6570\u6216\u63d0\u9ad8\u6027\u80fd\uff08\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u7ed3\u6784\uff09\u3002 PHP \u5f15\u7528\u4f20\u9012\uff1a\u6df1\u5165\u7406\u89e3\u51fd\u6570\u53c2\u6570\u4f20\u9012\u673a\u5236 \u7b80\u4ecb PHP \u4e2d\u6709\u4e24\u79cd\u51fd\u6570\u53c2\u6570\u4f20\u9012\u673a\u5236\uff1a\u503c\u4f20\u9012\u548c\u5f15\u7528\u4f20\u9012\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u53c2\u6570\u90fd\u88ab\u6309\u503c\u4f20\u9012\u3002\u503c\u4f20\u9012\u7b80\u5355\u5730\u5c06\u53c2\u6570\u7684\u4e00\u4e2a\u526f\u672c\u4f20\u9012\u7ed9\u51fd\u6570\uff0c\u800c\u5f15\u7528\u4f20\u9012\u5219\u5c06\u53c2\u6570\u7684\u539f\u59cb\u5185\u5b58\u5730\u5740\u4f20\u9012\u7ed9\u51fd\u6570\u3002 \u5f15\u7528\u4f20\u9012\u8bed\u6cd5 \u8981\u5c06\u53c2\u6570\u4f5c\u4e3a\u5f15\u7528\u4f20\u9012\uff0c\u8bf7\u4f7f\u7528\u7b26\u53f7 &amp; \u4f5c\u4e3a\u51fd\u6570\u53c2\u6570\u524d\u7f00\u3002\u4f8b\u5982\uff1a function foo(&amp;$param) { \/\/ \u5bf9 $param \u8fdb\u884c\u64cd\u4f5c\uff0c\u8fd9\u5c06\u5f71\u54cd\u539f\u59cb\u53d8\u91cf } \u4f55\u65f6\u4f7f\u7528\u5f15\u7528\u4f20\u9012\uff1f \u5f15\u7528\u4f20\u9012\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\u5f88\u6709\u7528\uff1a \u4fee\u6539\u4f20\u9012\u7ed9\u51fd\u6570\u7684\u53c2\u6570 \u901a\u8fc7\u8282\u7701\u5185\u5b58\u6765\u63d0\u9ad8\u6027\u80fd\uff08\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u7ed3\u6784\uff09 \u5b9e\u6218\u6848\u4f8b \u6848\u4f8b 1\uff1a\u4fee\u6539\u4f20\u9012\u7684\u53c2\u6570 $arr = [1, 2, 3]; function modifyArray(&amp;$arr) { $arr[0] = 10; } modifyArray($arr); echo implode(&#8220;, &#8220;, $arr); \/\/ \u8f93\u51fa\uff1a10, 2, 3 \u6848\u4f8b 2\uff1a\u63d0\u9ad8\u6027\u80fd [&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-47278","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47278","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=47278"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47278\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}