{"id":47390,"date":"2024-12-02T13:26:44","date_gmt":"2024-12-02T05:26:44","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47390\/"},"modified":"2024-12-02T13:26:44","modified_gmt":"2024-12-02T05:26:44","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%e5%92%8c%e6%8c%87%e9%92%88%e7%9a%84%e5%8c%ba%e5%88%ab","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47390\/","title":{"rendered":"PHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u548c\u6307\u9488\u7684\u533a\u522b"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u548c\u6307\u9488\u7684\u533a\u522b<\/h1>\n<p>\u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u548c\u6307\u9488\u7684\u533a\u522b\u300b<\/span>\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span><\/span>\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01<\/p>\n<p>\u5f15\u7528\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u51fd\u6570\u5916\u53d8\u91cf\u7684\u503c\uff0c\u800c\u6307\u9488\u53ea\u80fd\u4fee\u6539\u5176\u6307\u5411\u7684\u5185\u5b58\u3002\u5f15\u7528\u6309\u5f15\u7528\u4f20\u9012\uff0c\u8bed\u6cd5\u4e3a &amp;\uff0c\u800c\u6307\u9488\u6309\u503c\u4f20\u9012\uff0c\u8bed\u6cd5\u4e3a memory_get_reference() \u548c memory_set_reference()\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729915462671c6a4680b3f.jpg\" class=\"aligncenter\" title=\"PHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u548c\u6307\u9488\u7684\u533a\u522b\u63d2\u56fe\" alt=\"PHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u548c\u6307\u9488\u7684\u533a\u522b\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u51fd\u6570\u4e2d\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u548c\u6307\u9488\u7684\u533a\u522b<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>PHP \u5f15\u7528\u5141\u8bb8\u51fd\u6570\u4ee5\u9ad8\u6548\u7684\u65b9\u5f0f\u4fee\u6539\u539f\u59cb\u53d8\u91cf\u7684\u503c\u3002\u672c\u7bc7\u6587\u7ae0\u5c06\u89e3\u91ca PHP \u5f15\u7528\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff0c\u4ee5\u53ca\u5b83\u4eec\u4e0e\u6307\u9488\u7684\u533a\u522b\u3002<\/p>\n<p><strong>\u5f15\u7528<\/strong><\/p>\n<p>\u5f15\u7528\u7b26\u53f7\uff08&amp;\uff09\u5728\u53d8\u91cf\u540d\u524d\u4f7f\u7528\uff0c\u8868\u793a\u51fd\u6570\u4e2d\u7684\u53d8\u91cf\u6307\u5411\u539f\u59cb\u53d8\u91cf\u7684\u5185\u5b58\u5730\u5740\u3002\u5bf9\u5f15\u7528\u53d8\u91cf\u6240\u505a\u7684\u4efb\u4f55\u66f4\u6539\u90fd\u4f1a\u53cd\u6620\u5728\u539f\u59cb\u53d8\u91cf\u4e2d\u3002<\/p>\n<pre>&lt;?php\n    function increment(&amp;$number) {\n        $number++;\n    }\n\n    $number = 10;\n    increment($number);\n    echo $number; \/\/ \u8f93\u51fa\uff1a11\n?&gt;<\/pre>\n<p><strong>\u6307\u9488<\/strong><\/p>\n<p>PHP \u5e76\u4e0d\u50cf C \u90a3\u6837\u652f\u6301\u6307\u9488\uff0c\u4f46\u6709\u4e00\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u6a21\u62df\u7c7b\u4f3c\u7684\u884c\u4e3a\u3002\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528 <code>memory_get_reference()<\/code> \u548c <code>memory_set_reference()<\/code> \u51fd\u6570\u3002<\/p>\n<pre>&lt;?php\n    function increment($number) {\n        $numberPtr = memory_get_reference($number);\n        memory_set_reference($numberPtr, ++$number);\n    }\n\n    $number = 10;\n    increment($number);\n    echo $number; \/\/ \u8f93\u51fa\uff1a11\n?&gt;<\/pre>\n<p><strong>\u5f15\u7528\u4e0e\u6307\u9488\u7684\u533a\u522b<\/strong><\/p>\n<ul>\n<li><strong>\u4f20\u9012\u65b9\u5f0f\uff1a<\/strong>\u5f15\u7528\u6309\u5f15\u7528\u4f20\u9012\uff0c\u6307\u9488\u6309\u503c\u4f20\u9012\u3002<\/li>\n<li><strong>\u4fee\u6539\u6743\u9650\uff1a<\/strong>\u5f15\u7528\u53ef\u4ee5\u4fee\u6539\u539f\u59cb\u53d8\u91cf\uff0c\u800c\u6307\u9488\u53ef\u4ee5\u4fee\u6539\u5176\u6307\u5411\u7684\u5185\u5b58\u5730\u5740\u3002<\/li>\n<li><strong>\u8bed\u6cd5\uff1a<\/strong>\u5f15\u7528\u4f7f\u7528 <code>&amp;<\/code> \u7b26\u53f7\uff0c\u6307\u9488\u4f7f\u7528 <code>memory_get_reference()<\/code> \u548c <code>memory_set_reference()<\/code> \u51fd\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u8003\u8651\u4e00\u4e2a\u8d2d\u7269\u8f66\u7684\u4f8b\u5b50\uff0c\u91cc\u9762\u6709\u51e0\u4ef6\u5546\u54c1\uff1a<\/p>\n<pre>&lt;?php\n    $cart = [\n        ['name' =&gt; '\u82f9\u679c', 'price' =&gt; 10],\n        ['name' =&gt; '\u9999\u8549', 'price' =&gt; 5],\n        ['name' =&gt; '\u6a58\u5b50', 'price' =&gt; 7],\n    ];\n?&gt;<\/pre>\n<p>\u8981\u6253\u5370\u8d2d\u7269\u8f66\u7684\u603b\u4ef7\uff0c\u53ef\u4ee5\u4f7f\u7528\u5f15\u7528\u6765\u4fee\u6539\u6bcf\u4e2a\u5546\u54c1\u7684 <code>price<\/code>\uff1a<\/p>\n<pre>&lt;?php\n    function calculateTotalPrice(&amp;$cart) {\n        $totalPrice = 0;\n        foreach ($cart as &amp;$item) {\n            $totalPrice += $item['price'];\n        }\n        return $totalPrice;\n    }\n\n    echo calculateTotalPrice($cart); \/\/ \u8f93\u51fa\uff1a22\n?&gt;<\/pre>\n<p>\u901a\u8fc7\u4fee\u6539\u5b50\u6570\u7ec4\u4e2d\u7684\u5f15\u7528 <code>$item<\/code>\uff0c\u6211\u4eec\u6709\u6548\u5730\u4fee\u6539\u4e86\u539f\u59cb\u8d2d\u7269\u8f66\u7684 <code>price<\/code> \u503c\u3002<\/p>\n<p>\u7406\u8bba\u8981\u638c\u63e1\uff0c\u5b9e\u64cd\u4e0d\u80fd\u843d\uff01\u4ee5\u4e0a\u5173\u4e8e\u300aPHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u548c\u6307\u9488\u7684\u533a\u522b\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\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u548c\u6307\u9488\u7684\u533a\u522b \u5927\u5bb6\u597d\uff0c\u4eca\u5929\u672c\u4eba\u7ed9\u5927\u5bb6\u5e26\u6765\u6587\u7ae0\u300aPHP \u51fd\u6570\u4e2d\u5982\u4f55\u4f7f\u7528\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u548c\u6307\u9488\u7684\u533a\u522b\u300b\uff0c\u6587\u4e2d\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u90a3\u5c31\u8bf7\u5404\u4f4d\u670b\u53cb\u7ee7\u7eed\u770b\u4e0b\u53bb\u5427~\u5e0c\u671b\u80fd\u771f\u6b63\u5e2e\u5230\u4f60\u4eec\uff0c\u8c22\u8c22\uff01 \u5f15\u7528\u5141\u8bb8\u51fd\u6570\u4fee\u6539\u51fd\u6570\u5916\u53d8\u91cf\u7684\u503c\uff0c\u800c\u6307\u9488\u53ea\u80fd\u4fee\u6539\u5176\u6307\u5411\u7684\u5185\u5b58\u3002\u5f15\u7528\u6309\u5f15\u7528\u4f20\u9012\uff0c\u8bed\u6cd5\u4e3a &amp;\uff0c\u800c\u6307\u9488\u6309\u503c\u4f20\u9012\uff0c\u8bed\u6cd5\u4e3a memory_get_reference() \u548c memory_set_reference()\u3002 PHP \u51fd\u6570\u4e2d\u5f15\u7528\uff1a\u7406\u89e3\u5f15\u7528\u548c\u6307\u9488\u7684\u533a\u522b \u5f15\u8a00 PHP \u5f15\u7528\u5141\u8bb8\u51fd\u6570\u4ee5\u9ad8\u6548\u7684\u65b9\u5f0f\u4fee\u6539\u539f\u59cb\u53d8\u91cf\u7684\u503c\u3002\u672c\u7bc7\u6587\u7ae0\u5c06\u89e3\u91ca PHP \u5f15\u7528\u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff0c\u4ee5\u53ca\u5b83\u4eec\u4e0e\u6307\u9488\u7684\u533a\u522b\u3002 \u5f15\u7528 \u5f15\u7528\u7b26\u53f7\uff08&amp;\uff09\u5728\u53d8\u91cf\u540d\u524d\u4f7f\u7528\uff0c\u8868\u793a\u51fd\u6570\u4e2d\u7684\u53d8\u91cf\u6307\u5411\u539f\u59cb\u53d8\u91cf\u7684\u5185\u5b58\u5730\u5740\u3002\u5bf9\u5f15\u7528\u53d8\u91cf\u6240\u505a\u7684\u4efb\u4f55\u66f4\u6539\u90fd\u4f1a\u53cd\u6620\u5728\u539f\u59cb\u53d8\u91cf\u4e2d\u3002 &lt;?php function increment(&amp;$number) { $number++; } $number = 10; increment($number); echo $number; \/\/ \u8f93\u51fa\uff1a11 ?&gt; \u6307\u9488 PHP \u5e76\u4e0d\u50cf C \u90a3\u6837\u652f\u6301\u6307\u9488\uff0c\u4f46\u6709\u4e00\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u6a21\u62df\u7c7b\u4f3c\u7684\u884c\u4e3a\u3002\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528 memory_get_reference() \u548c memory_set_reference() \u51fd\u6570\u3002 &lt;?php function increment($number) { $numberPtr = memory_get_reference($number); memory_set_reference($numberPtr, ++$number); } $number = 10; [&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-47390","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47390","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=47390"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47390\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}