{"id":46927,"date":"2024-12-02T10:36:22","date_gmt":"2024-12-02T02:36:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/46927\/"},"modified":"2024-12-02T10:36:22","modified_gmt":"2024-12-02T02:36:22","slug":"php-%e5%87%bd%e6%95%b0%e5%bc%95%e7%94%a8%e4%bc%a0%e9%80%92%ef%bc%9a%e9%80%9a%e8%bf%87%e7%a4%ba%e4%be%8b%e6%8e%8c%e6%8f%a1%e5%85%b6%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/46927\/","title":{"rendered":"PHP \u51fd\u6570\u5f15\u7528\u4f20\u9012\uff1a\u901a\u8fc7\u793a\u4f8b\u638c\u63e1\u5176\u5e94\u7528"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u5f15\u7528\u4f20\u9012\uff1a\u901a\u8fc7\u793a\u4f8b\u638c\u63e1\u5176\u5e94\u7528<\/h1>\n<p>\u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\u7c73\u4e91\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u5f15\u7528\u4f20\u9012\uff1a\u901a\u8fc7\u793a\u4f8b\u638c\u63e1\u5176\u5e94\u7528\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p>PHP \u51fd\u6570\u5f15\u7528\u4f20\u9012\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u4f20\u9012\u7684\u53c2\u6570\u503c\uff0c\u800c\u975e\u503c\u4f20\u9012\u3002\u5b9e\u73b0\u5f15\u7528\u4f20\u9012\u9700\u8981\u5728\u51fd\u6570\u53c2\u6570\u524d\u9762\u6dfb\u52a0 &amp; \u7b26\uff0c\u4f8b\u5982 &amp;$param\u3002\u5f15\u7528\u4f20\u9012\u5728\u8868\u5355\u5904\u7406\u3001\u5bf9\u8c61\u65b9\u6cd5\u548c\u9700\u8981\u4fee\u6539\u539f\u59cb\u53d8\u91cf\u503c\u7684\u573a\u666f\u4e2d\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729854747671b7d1b970ad.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u5f15\u7528\u4f20\u9012\uff1a\u901a\u8fc7\u793a\u4f8b\u638c\u63e1\u5176\u5e94\u7528\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u5f15\u7528\u4f20\u9012\uff1a\u901a\u8fc7\u793a\u4f8b\u638c\u63e1\u5176\u5e94\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u5f15\u7528\u4f20\u9012\uff1a\u901a\u8fc7\u793a\u4f8b\u638c\u63e1\u5176\u5e94\u7528<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>PHP \u51fd\u6570\u53c2\u6570\u4f20\u9012\u53ef\u4ee5\u5206\u4e3a\u4e24\u79cd\u7c7b\u578b\uff1a\u503c\u4f20\u9012\u548c\u5f15\u7528\u4f20\u9012\u3002\u5f15\u7528\u4f20\u9012\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u4f20\u9012\u7684\u53c2\u6570\u503c\uff0c\u800c\u503c\u4f20\u9012\u5219\u4e0d\u4f1a\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8 PHP \u4e2d\u7684\u5f15\u7528\u4f20\u9012\uff0c\u5e76\u901a\u8fc7\u5b9e\u6218\u6848\u4f8b\u5c55\u793a\u5176\u5e94\u7528\u3002<\/p>\n<p><strong>\u503c\u4f20\u9012 vs. \u5f15\u7528\u4f20\u9012<\/strong><\/p>\n<p>\u5728<strong>\u503c\u4f20\u9012<\/strong>\u4e2d\uff0c\u51fd\u6570\u53c2\u6570\u7684\u503c\u88ab\u590d\u5236\u5230\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\u3002\u5bf9\u5c40\u90e8\u53d8\u91cf\u6240\u505a\u7684\u4efb\u4f55\u4fee\u6539\u90fd\u4e0d\u4f1a\u5f71\u54cd\u539f\u59cb\u503c\u3002<\/p>\n<pre>function addValue($num) {\n  $num += 10;\n  return $num;\n}\n\n$a = 5;\n$b = addValue($a);\n\necho $a; \/\/ \u8f93\u51fa 5\necho $b; \/\/ \u8f93\u51fa 15<\/pre>\n<p>\u5728<strong>\u5f15\u7528\u4f20\u9012<\/strong>\u4e2d\uff0c\u51fd\u6570\u53c2\u6570\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u5bf9\u539f\u59cb\u53d8\u91cf\u7684\u5f15\u7528\u3002\u5bf9\u51fd\u6570\u5185\u53d8\u91cf\u6240\u505a\u7684\u4efb\u4f55\u4fee\u6539\u90fd\u4f1a\u4fee\u6539\u539f\u59cb\u53d8\u91cf\u7684\u503c\u3002<\/p>\n<pre>function addValueByRef(&amp;$num) {\n  $num += 10;\n  return $num;\n}\n\n$a = 5;\naddValueByRef($a);\n\necho $a; \/\/ \u8f93\u51fa 15<\/pre>\n<p><strong>\u5982\u4f55\u5b9e\u73b0\u5f15\u7528\u4f20\u9012<\/strong><\/p>\n<p>\u8981\u5b9e\u73b0\u5f15\u7528\u4f20\u9012\uff0c\u9700\u8981\u5728\u51fd\u6570\u53c2\u6570\u524d\u9762\u6dfb\u52a0 <code>&amp;<\/code> \u7b26\u53f7\u3002<\/p>\n<pre>function myFunction(&amp;$param) {\n  \/\/ \u4fee\u6539 $param\n}<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u6848\u4f8b 1\uff1a\u8868\u5355\u5904\u7406<\/strong><\/p>\n<p>\u5f15\u7528\u4f20\u9012\u5728\u8868\u5355\u5904\u7406\u4e2d\u975e\u5e38\u6709\u7528\uff0c\u56e0\u4e3a\u60a8\u9700\u8981\u4fee\u6539\u539f\u59cb\u6570\u7ec4\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<pre>function processFormArray(&amp;$formData) {\n  \/\/ \u6e05\u7406\u5e76\u9a8c\u8bc1\u8868\u5355\u6570\u636e\n  \/\/ ...\n\n  \/\/ \u4fdd\u5b58\u66f4\u65b0\u540e\u7684\u6570\u636e\n  \/\/ ...\n}\n\n$formData = $_POST;\nprocessFormArray($formData);\n\n\/\/ \u60a8\u73b0\u5728\u53ef\u4ee5\u8bbf\u95ee\u5df2\u66f4\u65b0\u7684 $formData \u6570\u7ec4<\/pre>\n<p><strong>\u6848\u4f8b 2\uff1a\u5bf9\u8c61\u65b9\u6cd5<\/strong><\/p>\n<p>\u5f15\u7528\u4f20\u9012\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5bf9\u8c61\u65b9\u6cd5\uff0c\u5b83\u5141\u8bb8\u60a8\u4fee\u6539\u4f20\u9012\u7ed9\u65b9\u6cd5\u7684\u5bf9\u8c61\u3002<\/p>\n<pre>class User {\n  private $name;\n\n  public function setName(&amp;$name) {\n    $this-&gt;name = $name;\n  }\n}\n\n$user = new User();\n$user-&gt;setName('John Doe');\n\necho $user-&gt;getName(); \/\/ \u8f93\u51fa John Doe<\/pre>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u5f15\u7528\u4f20\u9012\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u5b83\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u4f20\u9012\u7684\u53c2\u6570\u503c\u3002\u5b83\u5728\u8868\u5355\u5904\u7406\u3001\u5bf9\u8c61\u65b9\u6cd5\u4ee5\u53ca\u9700\u8981\u4fee\u6539\u539f\u59cb\u53d8\u91cf\u503c\u7684\u4efb\u4f55\u5176\u4ed6\u60c5\u51b5\u4e0b\u90fd\u5f88\u6709\u7528\u3002\u901a\u8fc7\u7406\u89e3\u5f15\u7528\u4f20\u9012\u7684\u5de5\u4f5c\u539f\u7406\u53ca\u5176\u5e94\u7528\uff0c\u60a8\u53ef\u4ee5\u7f16\u5199\u66f4\u5f3a\u5927\u548c\u66f4\u6709\u6548\u7684 PHP \u4ee3\u7801\u3002<\/p>\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 \u51fd\u6570\u5f15\u7528\u4f20\u9012\uff1a\u901a\u8fc7\u793a\u4f8b\u638c\u63e1\u5176\u5e94\u7528 \u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\u7c73\u4e91\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u300aPHP \u51fd\u6570\u5f15\u7528\u4f20\u9012\uff1a\u901a\u8fc7\u793a\u4f8b\u638c\u63e1\u5176\u5e94\u7528\u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01 PHP \u51fd\u6570\u5f15\u7528\u4f20\u9012\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u4f20\u9012\u7684\u53c2\u6570\u503c\uff0c\u800c\u975e\u503c\u4f20\u9012\u3002\u5b9e\u73b0\u5f15\u7528\u4f20\u9012\u9700\u8981\u5728\u51fd\u6570\u53c2\u6570\u524d\u9762\u6dfb\u52a0 &amp; \u7b26\uff0c\u4f8b\u5982 &amp;$param\u3002\u5f15\u7528\u4f20\u9012\u5728\u8868\u5355\u5904\u7406\u3001\u5bf9\u8c61\u65b9\u6cd5\u548c\u9700\u8981\u4fee\u6539\u539f\u59cb\u53d8\u91cf\u503c\u7684\u573a\u666f\u4e2d\u975e\u5e38\u6709\u7528\u3002 PHP \u51fd\u6570\u5f15\u7528\u4f20\u9012\uff1a\u901a\u8fc7\u793a\u4f8b\u638c\u63e1\u5176\u5e94\u7528 \u5f15\u8a00 PHP \u51fd\u6570\u53c2\u6570\u4f20\u9012\u53ef\u4ee5\u5206\u4e3a\u4e24\u79cd\u7c7b\u578b\uff1a\u503c\u4f20\u9012\u548c\u5f15\u7528\u4f20\u9012\u3002\u5f15\u7528\u4f20\u9012\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u4f20\u9012\u7684\u53c2\u6570\u503c\uff0c\u800c\u503c\u4f20\u9012\u5219\u4e0d\u4f1a\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8 PHP \u4e2d\u7684\u5f15\u7528\u4f20\u9012\uff0c\u5e76\u901a\u8fc7\u5b9e\u6218\u6848\u4f8b\u5c55\u793a\u5176\u5e94\u7528\u3002 \u503c\u4f20\u9012 vs. \u5f15\u7528\u4f20\u9012 \u5728\u503c\u4f20\u9012\u4e2d\uff0c\u51fd\u6570\u53c2\u6570\u7684\u503c\u88ab\u590d\u5236\u5230\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\u3002\u5bf9\u5c40\u90e8\u53d8\u91cf\u6240\u505a\u7684\u4efb\u4f55\u4fee\u6539\u90fd\u4e0d\u4f1a\u5f71\u54cd\u539f\u59cb\u503c\u3002 function addValue($num) { $num += 10; return $num; } $a = 5; $b = addValue($a); echo $a; \/\/ \u8f93\u51fa 5 echo $b; \/\/ \u8f93\u51fa 15 \u5728\u5f15\u7528\u4f20\u9012\u4e2d\uff0c\u51fd\u6570\u53c2\u6570\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u5bf9\u539f\u59cb\u53d8\u91cf\u7684\u5f15\u7528\u3002\u5bf9\u51fd\u6570\u5185\u53d8\u91cf\u6240\u505a\u7684\u4efb\u4f55\u4fee\u6539\u90fd\u4f1a\u4fee\u6539\u539f\u59cb\u53d8\u91cf\u7684\u503c\u3002 function addValueByRef(&amp;$num) { $num += 10; return $num; } [&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-46927","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46927","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=46927"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/46927\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=46927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=46927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=46927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}