{"id":47759,"date":"2024-12-02T08:51:56","date_gmt":"2024-12-02T00:51:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47759\/"},"modified":"2024-12-02T08:51:56","modified_gmt":"2024-12-02T00:51:56","slug":"php-%e5%87%bd%e6%95%b0%e4%b8%ad%e7%9a%84%e5%bc%95%e7%94%a8%e6%98%af%e5%90%a6%e9%80%82%e7%94%a8%e4%ba%8e%e6%95%b0%e7%bb%84%e5%92%8c%e5%af%b9%e8%b1%a1%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47759\/","title":{"rendered":"PHP \u51fd\u6570\u4e2d\u7684\u5f15\u7528\u662f\u5426\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u4e2d\u7684\u5f15\u7528\u662f\u5426\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\uff1f<\/h1>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u7c73\u4e91\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300aPHP \u51fd\u6570\u4e2d\u7684\u5f15\u7528\u662f\u5426\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01<\/p>\n<p>\u662f\u7684\uff0cPHP \u51fd\u6570\u4e2d\u7684\u5f15\u7528\u540c\u6837\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\u3002\u901a\u8fc7\u5728\u53c2\u6570\u524d\u52a0\u4e0a &amp; \u548c\u5bf9\u8c61\u64cd\u4f5c\u7b26 -&gt;\uff0c\u53ef\u4ee5\u4f20\u9012\u5bf9\u6570\u7ec4\u548c\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u4ece\u800c\u5728\u51fd\u6570\u5185\u5bf9\u5176\u8fdb\u884c\u4fee\u6539\uff0c\u5e76\u53cd\u6620\u5728\u51fd\u6570\u5916\u7684\u539f\u59cb\u53d8\u91cf\u4e0a\u3002\u8fd9\u6709\u52a9\u4e8e\u9ad8\u6548\u5904\u7406\u5927\u578b\u6570\u636e\u7ed3\u6784\u6216\u4fee\u6539\u590d\u6742\u5bf9\u8c61\u7684\u5c5e\u6027\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729934782671cb5beb0842.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u4e2d\u7684\u5f15\u7528\u662f\u5426\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\uff1f\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u4e2d\u7684\u5f15\u7528\u662f\u5426\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u4e2d\u7684\u5f15\u7528\u662f\u5426\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\uff1f<\/strong><\/p>\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n<p>PHP \u4e2d\u7684\u5f15\u7528\u5141\u8bb8\u6211\u4eec\u901a\u8fc7\u5171\u4eab\u5185\u5b58\u7684\u65b9\u5f0f\u64cd\u4f5c\u53d8\u91cf\uff0c\u6267\u884c\u6548\u7387\u66f4\u9ad8\u3002\u5728\u51fd\u6570\u4e2d\u4f7f\u7528\u5f15\u7528\u65f6\uff0c\u5bf9\u5176\u8fdb\u884c\u7684\u4efb\u4f55\u4fee\u6539\u90fd\u4f1a\u53cd\u6620\u5728\u51fd\u6570\u5916\u90e8\u7684\u539f\u59cb\u53d8\u91cf\u4e0a\u3002<\/p>\n<p><strong>\u6570\u7ec4\u548c\u5bf9\u8c61\u662f\u5426\u53ef\u4ee5\u4f7f\u7528\u5f15\u7528\uff1f<\/strong><\/p>\n<p>\u662f\u7684\uff0cPHP \u4e2d\u7684\u5f15\u7528\u540c\u6837\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\u3002<\/p>\n<p><strong>\u5bf9\u4e8e\u6570\u7ec4\uff1a<\/strong><\/p>\n<p>\u901a\u8fc7\u5728\u51fd\u6570\u7684\u53c2\u6570\u524d\u52a0\u4e0a <code>&amp;<\/code> \u7b26\u53f7\uff0c\u5373\u53ef\u4f20\u9012\u6570\u7ec4\u5f15\u7528\u3002<\/p>\n<pre>function myFunction(&amp;$array) {\n  $array[] = \"\u65b0\u5143\u7d20\";\n}<\/pre>\n<p><strong>\u5bf9\u4e8e\u5bf9\u8c61\uff1a<\/strong><\/p>\n<p>\u4f20\u9012\u5bf9\u8c61\u5f15\u7528\u4e0e\u4f20\u9012\u6570\u7ec4\u5f15\u7528\u7c7b\u4f3c\uff0c\u53ea\u4e0d\u8fc7\u9700\u8981\u4f7f\u7528\u5bf9\u8c61\u64cd\u4f5c\u7b26 <code>-&gt;<\/code> \u800c\u4e0d\u662f\u6570\u7ec4\u7d22\u5f15 <code>[]<\/code>\u3002<\/p>\n<pre>class MyClass {\n  private $property;\n}\n\nfunction myFunction(MyClass &amp;$object) {\n  $object-&gt;property = \"\u65b0\u503c\";\n}<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u6848\u4f8b 1\uff1a\u66f4\u65b0\u6570\u7ec4<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a &#8220;names&#8221; \u7684\u6570\u7ec4\uff0c\u5305\u542b\u4e86\u51e0\u4e2a\u540d\u5b57\uff1a<\/p>\n<pre>$names = [\"John\", \"Mary\", \"Bob\"];<\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u5f15\u7528\u6765\u5411\u8be5\u6570\u7ec4\u6dfb\u52a0\u4e00\u4e2a\u65b0\u540d\u5b57\uff1a<\/p>\n<pre>function addName(&amp;$array, $name) {\n  $array[] = $name;\n}\n\naddName($names, \"Alice\");\n\necho implode(\", \", $names); \/\/ \u8f93\u51fa\uff1aJohn, Mary, Bob, Alice<\/pre>\n<p><strong>\u6848\u4f8b 2\uff1a\u4fee\u6539\u5bf9\u8c61\u5c5e\u6027<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a &#8220;person&#8221; \u7684\u5bf9\u8c61\uff0c\u5305\u542b\u4e86 name \u548c age \u5c5e\u6027\uff1a<\/p>\n<pre>class Person {\n  public $name;\n  public $age;\n}\n\n$person = new Person();\n$person-&gt;name = \"John\";\n$person-&gt;age = 30;<\/pre>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u51fd\u6570\u5f15\u7528\u6765\u4fee\u6539\u5bf9\u8c61\u7684 name \u5c5e\u6027\uff1a<\/p>\n<pre>function changeName(Person &amp;$person, $newName) {\n  $person-&gt;name = $newName;\n}\n\nchangeName($person, \"Mary\");\n\necho $person-&gt;name; \/\/ \u8f93\u51fa\uff1aMary<\/pre>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>\u901a\u8fc7\u5728 PHP \u51fd\u6570\u4e2d\u4f7f\u7528\u5f15\u7528\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u64cd\u4f5c\u6570\u7ec4\u548c\u5bf9\u8c61\uff0c\u56e0\u4e3a\u4fee\u6539\u51fd\u6570\u5185\u7684\u526f\u672c\u4f1a\u81ea\u52a8\u53cd\u6620\u5728\u5916\u90e8\u7684\u539f\u59cb\u53d8\u91cf\u4e0a\u3002\u8fd9\u5728\u9700\u8981\u5904\u7406\u5927\u578b\u6570\u636e\u7ed3\u6784\u6216\u4fee\u6539\u590d\u6742\u5bf9\u8c61\u7684\u5c5e\u6027\u65f6\u975e\u5e38\u6709\u7528\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\u4e2d\u7684\u5f15\u7528\u662f\u5426\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\uff1f \u5bf9\u4e8e\u4e00\u4e2a\u6587\u7ae0\u5f00\u53d1\u8005\u6765\u8bf4\uff0c\u7262\u56fa\u624e\u5b9e\u7684\u57fa\u7840\u662f\u5341\u5206\u91cd\u8981\u7684\uff0c\u7c73\u4e91\u5c31\u6765\u5e26\u5927\u5bb6\u4e00\u70b9\u70b9\u7684\u638c\u63e1\u57fa\u7840\u77e5\u8bc6\u70b9\u3002\u4eca\u5929\u672c\u7bc7\u6587\u7ae0\u5e26\u5927\u5bb6\u4e86\u89e3\u300aPHP \u51fd\u6570\u4e2d\u7684\u5f15\u7528\u662f\u5426\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\uff1f\u300b\uff0c\u4e3b\u8981\u4ecb\u7ecd\u4e86\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u5feb\u70b9\u6536\u85cf\u8d77\u6765\u5427\uff0c\u5426\u5219\u9700\u8981\u65f6\u5c31\u627e\u4e0d\u5230\u4e86\uff01 \u662f\u7684\uff0cPHP \u51fd\u6570\u4e2d\u7684\u5f15\u7528\u540c\u6837\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\u3002\u901a\u8fc7\u5728\u53c2\u6570\u524d\u52a0\u4e0a &amp; \u548c\u5bf9\u8c61\u64cd\u4f5c\u7b26 -&gt;\uff0c\u53ef\u4ee5\u4f20\u9012\u5bf9\u6570\u7ec4\u548c\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u4ece\u800c\u5728\u51fd\u6570\u5185\u5bf9\u5176\u8fdb\u884c\u4fee\u6539\uff0c\u5e76\u53cd\u6620\u5728\u51fd\u6570\u5916\u7684\u539f\u59cb\u53d8\u91cf\u4e0a\u3002\u8fd9\u6709\u52a9\u4e8e\u9ad8\u6548\u5904\u7406\u5927\u578b\u6570\u636e\u7ed3\u6784\u6216\u4fee\u6539\u590d\u6742\u5bf9\u8c61\u7684\u5c5e\u6027\u3002 PHP \u51fd\u6570\u4e2d\u7684\u5f15\u7528\u662f\u5426\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\uff1f \u7b80\u4ecb PHP \u4e2d\u7684\u5f15\u7528\u5141\u8bb8\u6211\u4eec\u901a\u8fc7\u5171\u4eab\u5185\u5b58\u7684\u65b9\u5f0f\u64cd\u4f5c\u53d8\u91cf\uff0c\u6267\u884c\u6548\u7387\u66f4\u9ad8\u3002\u5728\u51fd\u6570\u4e2d\u4f7f\u7528\u5f15\u7528\u65f6\uff0c\u5bf9\u5176\u8fdb\u884c\u7684\u4efb\u4f55\u4fee\u6539\u90fd\u4f1a\u53cd\u6620\u5728\u51fd\u6570\u5916\u90e8\u7684\u539f\u59cb\u53d8\u91cf\u4e0a\u3002 \u6570\u7ec4\u548c\u5bf9\u8c61\u662f\u5426\u53ef\u4ee5\u4f7f\u7528\u5f15\u7528\uff1f \u662f\u7684\uff0cPHP \u4e2d\u7684\u5f15\u7528\u540c\u6837\u9002\u7528\u4e8e\u6570\u7ec4\u548c\u5bf9\u8c61\u3002 \u5bf9\u4e8e\u6570\u7ec4\uff1a \u901a\u8fc7\u5728\u51fd\u6570\u7684\u53c2\u6570\u524d\u52a0\u4e0a &amp; \u7b26\u53f7\uff0c\u5373\u53ef\u4f20\u9012\u6570\u7ec4\u5f15\u7528\u3002 function myFunction(&amp;$array) { $array[] = &#8220;\u65b0\u5143\u7d20&#8221;; } \u5bf9\u4e8e\u5bf9\u8c61\uff1a \u4f20\u9012\u5bf9\u8c61\u5f15\u7528\u4e0e\u4f20\u9012\u6570\u7ec4\u5f15\u7528\u7c7b\u4f3c\uff0c\u53ea\u4e0d\u8fc7\u9700\u8981\u4f7f\u7528\u5bf9\u8c61\u64cd\u4f5c\u7b26 -&gt; \u800c\u4e0d\u662f\u6570\u7ec4\u7d22\u5f15 []\u3002 class MyClass { private $property; } function myFunction(MyClass &amp;$object) { $object-&gt;property = &#8220;\u65b0\u503c&#8221;; } \u5b9e\u6218\u6848\u4f8b \u6848\u4f8b 1\uff1a\u66f4\u65b0\u6570\u7ec4 \u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u540d\u4e3a &#8220;names&#8221; \u7684\u6570\u7ec4\uff0c\u5305\u542b\u4e86\u51e0\u4e2a\u540d\u5b57\uff1a $names = [&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-47759","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47759","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=47759"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47759\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}