{"id":47906,"date":"2024-12-02T13:35:44","date_gmt":"2024-12-02T05:35:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47906\/"},"modified":"2024-12-02T13:35:44","modified_gmt":"2024-12-02T05:35:44","slug":"php%e5%87%bd%e6%95%b0%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87%e5%bc%95%e7%94%a8%e4%bc%a0%e9%80%92%e5%8f%82%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47906\/","title":{"rendered":"PHP\u51fd\u6570\u5982\u4f55\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP\u51fd\u6570\u5982\u4f55\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\uff1f<\/h1>\n<p>\u73cd\u60dc\u65f6\u95f4\uff0c\u52e4\u594b\u5b66\u4e60\uff01\u4eca\u5929\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP\u51fd\u6570\u5982\u4f55\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\uff1f\u300b<\/span>\uff0c\u6b63\u6587\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u6216\u8005\u662f\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u6709\u7591\u95ee\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u6211\uff01\u540e\u9762\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u5185\u5bb9\u7684\uff0c\u5e0c\u671b\u90fd\u80fd\u5e2e\u5230\u6b63\u5728\u5b66\u4e60\u7684\u5927\u5bb6\uff01<\/p>\n<p>PHP \u51fd\u6570\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a\u5728\u53c2\u6570\u524d\u6dfb\u52a0 &amp; \u7b26\u53f7\uff0c\u5982 function incrementByReference(&amp; $num) {}\u8c03\u7528\u65f6\u4f20\u9012\u53d8\u91cf\u5f15\u7528\uff0c\u5982 incrementByReference($number)\u53ef\u4ee5\u63d0\u9ad8\u51fd\u6570\u6548\u7387\uff0c\u4fee\u6539\u53c2\u6570\u4f1a\u5f71\u54cd\u5916\u90e8\u53d8\u91cf\u9700\u6ce8\u610f\u907f\u514d\u540c\u4e00\u53d8\u91cf\u5f15\u7528\u548c\u503c\u4f20\u9012\uff0c\u8c28\u614e\u4f7f\u7528\u5168\u5c40\u53d8\u91cf<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729942054671cd2261bccc.jpg\" class=\"aligncenter\" title=\"PHP\u51fd\u6570\u5982\u4f55\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\uff1f\u63d2\u56fe\" alt=\"PHP\u51fd\u6570\u5982\u4f55\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u5982\u4f55\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>\u4f20\u9012\u53c2\u6570\u662f\u51fd\u6570\u7684\u57fa\u672c\u529f\u80fd\u3002\u5728 PHP \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u503c\u4f20\u9012\u548c\u5f15\u7528\u4f20\u9012\u4e24\u79cd\u65b9\u5f0f\u4f20\u9012\u53c2\u6570\u3002\u901a\u8fc7\u503c\u4f20\u9012\uff0c\u51fd\u6570\u4f1a\u521b\u5efa\u53c2\u6570\u526f\u672c\uff0c\u800c\u901a\u8fc7\u5f15\u7528\u4f20\u9012\uff0c\u51fd\u6570\u4f1a\u64cd\u4f5c\u5b9e\u9645\u53c2\u6570\u3002<\/p>\n<p><strong>\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570<\/strong><\/p>\n<p>\u8981\u5728 PHP \u4e2d\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\uff0c\u53ef\u4ee5\u5728\u53c2\u6570\u524d\u9762\u6dfb\u52a0\u4e00\u4e2a <code>&amp;<\/code> \u7b26\u53f7\uff1a<\/p>\n<pre>function incrementByReference(&amp;$num) {\n  $num++;\n}<\/pre>\n<p>\u8c03\u7528\u6b64\u51fd\u6570\u65f6\uff0c\u6211\u4eec\u4f20\u9012\u4e00\u4e2a\u53d8\u91cf\u7684\u5f15\u7528\uff0c\u800c\u4e0d\u662f\u53d8\u91cf\u672c\u8eab\uff1a<\/p>\n<pre>$number = 5;\nincrementByReference($number);\n\necho $number; \/\/ \u8f93\u51fa 6<\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u51fd\u6570\u901a\u8fc7\u5f15\u7528\u4fee\u6539\u4e86\u5916\u90e8\u53d8\u91cf\u7684\u503c\uff0c\u4ece\u800c\u4ea7\u751f\u4e86\u9884\u671f\u7684\u7ed3\u679c\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a <code>swap<\/code> \u51fd\u6570\uff0c\u5f53\u4f20\u9012\u4e24\u4e2a\u53d8\u91cf\u65f6\uff0c\u5b83\u4f1a\u4ea4\u6362\u8fd9\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\u3002\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\u53ef\u4ee5\u8ba9\u8fd9\u4e2a\u51fd\u6570\u66f4\u52a0\u9ad8\u6548\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>function swapByReference(&amp;$a, &amp;$b) {\n  $temp = $a;\n  $a = $b;\n  $b = $temp;\n}<\/pre>\n<p>\u4f7f\u7528\u6b64\u51fd\u6570\uff1a<\/p>\n<pre>$x = 1;\n$y = 2;\n\nswapByReference($x, $y);\n\necho \"x: $x, y: $y\"; \/\/ \u8f93\u51fa \"x: 2, y: 1\"<\/pre>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<p>\u867d\u7136\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\u53ef\u4ee5\u63d0\u9ad8\u51fd\u6570\u7684\u6548\u7387\uff0c\u4f46\u4e5f\u5b58\u5728\u4e00\u4e9b\u9700\u8981\u6ce8\u610f\u7684\u4e8b\u9879\uff1a<\/p>\n<ul>\n<li>\u5bf9\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u7684\u53c2\u6570\u8fdb\u884c\u4fee\u6539\uff0c\u4f1a\u5f71\u54cd\u5916\u90e8\u53d8\u91cf\u3002<\/li>\n<li>\u907f\u514d\u5728\u540c\u4e00\u51fd\u6570\u4e2d\u901a\u8fc7\u5f15\u7528\u548c\u503c\u4f20\u9012\u540c\u4e00\u53d8\u91cf\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u610f\u60f3\u4e0d\u5230\u7684\u884c\u4e3a\u3002<\/li>\n<li>\u8c28\u614e\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\uff0c\u56e0\u4e3a\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u7684\u53c2\u6570\u53ef\u80fd\u4f1a\u610f\u5916\u5730\u4fee\u6539\u5b83\u4eec\u3002<\/li>\n<\/ul>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aPHP\u51fd\u6570\u5982\u4f55\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\uff1f\u300b\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u5927\u5bb6\u90fd\u638c\u63e1\u4e86\u5427\uff01\u5982\u679c\u60f3\u8981\u7ee7\u7eed\u63d0\u5347\u81ea\u5df1\u7684\u80fd\u529b\uff0c\u90a3\u4e48\u5c31\u6765\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u5427\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u51fd\u6570\u5982\u4f55\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\uff1f \u73cd\u60dc\u65f6\u95f4\uff0c\u52e4\u594b\u5b66\u4e60\uff01\u4eca\u5929\u7ed9\u5927\u5bb6\u5e26\u6765\u300aPHP\u51fd\u6570\u5982\u4f55\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\uff1f\u300b\uff0c\u6b63\u6587\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\u7b49\u7b49\uff0c\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\u6587\u7ae0\uff0c\u6216\u8005\u662f\u5bf9\u6587\u7ae0\u6709\u7591\u95ee\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u6211\uff01\u540e\u9762\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u5185\u5bb9\u7684\uff0c\u5e0c\u671b\u90fd\u80fd\u5e2e\u5230\u6b63\u5728\u5b66\u4e60\u7684\u5927\u5bb6\uff01 PHP \u51fd\u6570\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\u7684\u65b9\u6cd5\u5982\u4e0b\uff1a\u5728\u53c2\u6570\u524d\u6dfb\u52a0 &amp; \u7b26\u53f7\uff0c\u5982 function incrementByReference(&amp; $num) {}\u8c03\u7528\u65f6\u4f20\u9012\u53d8\u91cf\u5f15\u7528\uff0c\u5982 incrementByReference($number)\u53ef\u4ee5\u63d0\u9ad8\u51fd\u6570\u6548\u7387\uff0c\u4fee\u6539\u53c2\u6570\u4f1a\u5f71\u54cd\u5916\u90e8\u53d8\u91cf\u9700\u6ce8\u610f\u907f\u514d\u540c\u4e00\u53d8\u91cf\u5f15\u7528\u548c\u503c\u4f20\u9012\uff0c\u8c28\u614e\u4f7f\u7528\u5168\u5c40\u53d8\u91cf PHP \u51fd\u6570\u5982\u4f55\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570 \u5f15\u8a00 \u4f20\u9012\u53c2\u6570\u662f\u51fd\u6570\u7684\u57fa\u672c\u529f\u80fd\u3002\u5728 PHP \u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u503c\u4f20\u9012\u548c\u5f15\u7528\u4f20\u9012\u4e24\u79cd\u65b9\u5f0f\u4f20\u9012\u53c2\u6570\u3002\u901a\u8fc7\u503c\u4f20\u9012\uff0c\u51fd\u6570\u4f1a\u521b\u5efa\u53c2\u6570\u526f\u672c\uff0c\u800c\u901a\u8fc7\u5f15\u7528\u4f20\u9012\uff0c\u51fd\u6570\u4f1a\u64cd\u4f5c\u5b9e\u9645\u53c2\u6570\u3002 \u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570 \u8981\u5728 PHP \u4e2d\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\uff0c\u53ef\u4ee5\u5728\u53c2\u6570\u524d\u9762\u6dfb\u52a0\u4e00\u4e2a &amp; \u7b26\u53f7\uff1a function incrementByReference(&amp;$num) { $num++; } \u8c03\u7528\u6b64\u51fd\u6570\u65f6\uff0c\u6211\u4eec\u4f20\u9012\u4e00\u4e2a\u53d8\u91cf\u7684\u5f15\u7528\uff0c\u800c\u4e0d\u662f\u53d8\u91cf\u672c\u8eab\uff1a $number = 5; incrementByReference($number); echo $number; \/\/ \u8f93\u51fa 6 \u53ef\u4ee5\u770b\u5230\uff0c\u51fd\u6570\u901a\u8fc7\u5f15\u7528\u4fee\u6539\u4e86\u5916\u90e8\u53d8\u91cf\u7684\u503c\uff0c\u4ece\u800c\u4ea7\u751f\u4e86\u9884\u671f\u7684\u7ed3\u679c\u3002 \u5b9e\u6218\u6848\u4f8b \u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a swap \u51fd\u6570\uff0c\u5f53\u4f20\u9012\u4e24\u4e2a\u53d8\u91cf\u65f6\uff0c\u5b83\u4f1a\u4ea4\u6362\u8fd9\u4e24\u4e2a\u53d8\u91cf\u7684\u503c\u3002\u901a\u8fc7\u5f15\u7528\u4f20\u9012\u53c2\u6570\u53ef\u4ee5\u8ba9\u8fd9\u4e2a\u51fd\u6570\u66f4\u52a0\u9ad8\u6548\uff0c\u5982\u4e0b\u6240\u793a\uff1a function swapByReference(&amp;$a, &amp;$b) { $temp = $a; $a = $b; $b = [&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-47906","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47906","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=47906"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47906\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47906"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47906"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47906"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}