{"id":48750,"date":"2024-12-02T16:01:28","date_gmt":"2024-12-02T08:01:28","guid":{"rendered":"https:\/\/fwq.ai\/blog\/48750\/"},"modified":"2024-12-02T16:01:28","modified_gmt":"2024-12-02T08:01:28","slug":"php-%e5%a4%9a%e7%bb%b4%e6%95%b0%e7%bb%84%e4%b8%ad%ef%bc%8c%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96%e6%8c%87%e5%ae%9a%e9%94%ae%e5%90%8d%e5%90%8c%e7%ba%a7%e5%89%8d%e4%b8%80%e4%b8%aa%e6%95%b0%e7%bb%84","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/48750\/","title":{"rendered":"PHP \u591a\u7ef4\u6570\u7ec4\u4e2d\uff0c\u5982\u4f55\u83b7\u53d6\u6307\u5b9a\u952e\u540d\u540c\u7ea7\u524d\u4e00\u4e2a\u6570\u7ec4\u7684\u5185\u5bb9\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u591a\u7ef4\u6570\u7ec4\u4e2d\uff0c\u5982\u4f55\u83b7\u53d6\u6307\u5b9a\u952e\u540d\u540c\u7ea7\u524d\u4e00\u4e2a\u6570\u7ec4\u7684\u5185\u5bb9\uff1f<\/h1>\n<p>\u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u591a\u7ef4\u6570\u7ec4\u4e2d\uff0c\u5982\u4f55\u83b7\u53d6\u6307\u5b9a\u952e\u540d\u540c\u7ea7\u524d\u4e00\u4e2a\u6570\u7ec4\u7684\u5185\u5bb9\uff1f\u300b<\/span>\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241030\/1730299890672247f270239.jpg\" class=\"aligncenter\" title=\"PHP \u591a\u7ef4\u6570\u7ec4\u4e2d\uff0c\u5982\u4f55\u83b7\u53d6\u6307\u5b9a\u952e\u540d\u540c\u7ea7\u524d\u4e00\u4e2a\u6570\u7ec4\u7684\u5185\u5bb9\uff1f\u63d2\u56fe\" alt=\"PHP \u591a\u7ef4\u6570\u7ec4\u4e2d\uff0c\u5982\u4f55\u83b7\u53d6\u6307\u5b9a\u952e\u540d\u540c\u7ea7\u524d\u4e00\u4e2a\u6570\u7ec4\u7684\u5185\u5bb9\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>php \u591a\u7ef4\u6570\u7ec4\u83b7\u53d6\u540c\u7ea7\u524d\u4e00\u4e2a\u6570\u7ec4<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u7ed9\u5b9a\u4e00\u4e2a\u591a\u7ef4\u6570\u7ec4\uff0c\u5982\u4f55\u901a\u8fc7\u4e00\u4e2a\u51fd\u6570\u6839\u636e\u4e00\u4e2a\u201c\u952e\u540d\u201d\u83b7\u53d6\u5230\u540c\u7ea7\u7684\u524d\u4e00\u4e2a\u6570\u7ec4\u7684\u5185\u5bb9\uff1f<\/p>\n<p>\u4f8b\u5982\uff0c\u7ed9\u5b9a\u4ee5\u4e0b\u6570\u7ec4\uff1a<\/p>\n<pre>$all = [];\n$a = [\"horse\" =&gt; \"0\", \"dog\" =&gt; \"1\", \"cat\" =&gt; \"2\"];\n$b = [\"horse\" =&gt; \"a\", \"dog\" =&gt; \"b\", \"cat\" =&gt; \"c\"];\n$c = [\"horse\" =&gt; \"a1\", \"dog\" =&gt; \"b2\", \"cat\" =&gt; \"c3\"];\n$all[\"123456\"][\"511\"] = $a;\n$all[\"123456\"][\"523\"] = $b;\n$all[\"123456\"][\"607\"] = $c;\nvar_dump($all);<\/pre>\n<p>\u5982\u4f55\u901a\u8fc7\u952e\u540d\u201c523\u201d\u83b7\u53d6\u5230\u952e\u540d\u201c511\u201d\u7684\u5185\u5bb9\uff1f<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51fd\u6570\u83b7\u53d6\u540c\u7ea7\u524d\u4e00\u4e2a\u6570\u7ec4\u7684\u5185\u5bb9\uff1a<\/p>\n<pre>function getpreviousarray($all, $key) {\n    $keys = array_keys($all);\n    $index = array_search($key, $keys);\n    if ($index &gt; 0) {\n        return $all[$keys[$index - 1]];\n    }\n    return null;\n}<\/pre>\n<p><strong>\u4f7f\u7528\u65b9\u5f0f\uff1a<\/strong><\/p>\n<pre>$previousarray = getpreviousarray($all, \"523\");\nvar_dump($previousarray);<\/pre>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<pre>array(3) {\n  [\"Horse\"] =&gt; string(1) \"0\"\n  [\"Dog\"] =&gt; string(1) \"1\"\n  [\"Cat\"] =&gt; string(1) \"2\"\n}<\/pre>\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 \u591a\u7ef4\u6570\u7ec4\u4e2d\uff0c\u5982\u4f55\u83b7\u53d6\u6307\u5b9a\u952e\u540d\u540c\u7ea7\u524d\u4e00\u4e2a\u6570\u7ec4\u7684\u5185\u5bb9\uff1f \u4eca\u65e5\u4e0d\u80af\u57cb\u5934\uff0c\u660e\u65e5\u4f55\u4ee5\u62ac\u5934\uff01\u6bcf\u65e5\u4e00\u53e5\u52aa\u529b\u81ea\u5df1\u7684\u8bdd\u54c8\u54c8~\u54c8\u55bd\uff0c\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u300aPHP \u591a\u7ef4\u6570\u7ec4\u4e2d\uff0c\u5982\u4f55\u83b7\u53d6\u6307\u5b9a\u952e\u540d\u540c\u7ea7\u524d\u4e00\u4e2a\u6570\u7ec4\u7684\u5185\u5bb9\uff1f\u300b\uff0c\u4e3b\u8981\u5185\u5bb9\u662f\u8bb2\u89e3\u7b49\u7b49\uff0c\u611f\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u6536\u85cf\u6216\u8005\u6709\u66f4\u597d\u7684\u5efa\u8bae\u5728\u8bc4\u8bba\u63d0\u51fa\uff0c\u6211\u90fd\u4f1a\u8ba4\u771f\u770b\u7684\uff01\u5927\u5bb6\u4e00\u8d77\u8fdb\u6b65\uff0c\u4e00\u8d77\u5b66\u4e60\uff01 php \u591a\u7ef4\u6570\u7ec4\u83b7\u53d6\u540c\u7ea7\u524d\u4e00\u4e2a\u6570\u7ec4 \u95ee\u9898\uff1a \u7ed9\u5b9a\u4e00\u4e2a\u591a\u7ef4\u6570\u7ec4\uff0c\u5982\u4f55\u901a\u8fc7\u4e00\u4e2a\u51fd\u6570\u6839\u636e\u4e00\u4e2a\u201c\u952e\u540d\u201d\u83b7\u53d6\u5230\u540c\u7ea7\u7684\u524d\u4e00\u4e2a\u6570\u7ec4\u7684\u5185\u5bb9\uff1f \u4f8b\u5982\uff0c\u7ed9\u5b9a\u4ee5\u4e0b\u6570\u7ec4\uff1a $all = []; $a = [&#8220;horse&#8221; =&gt; &#8220;0&#8221;, &#8220;dog&#8221; =&gt; &#8220;1&#8221;, &#8220;cat&#8221; =&gt; &#8220;2&#8221;]; $b = [&#8220;horse&#8221; =&gt; &#8220;a&#8221;, &#8220;dog&#8221; =&gt; &#8220;b&#8221;, &#8220;cat&#8221; =&gt; &#8220;c&#8221;]; $c = [&#8220;horse&#8221; =&gt; &#8220;a1&#8221;, &#8220;dog&#8221; =&gt; &#8220;b2&#8221;, &#8220;cat&#8221; =&gt; &#8220;c3&#8221;]; $all[&#8220;123456&#8221;][&#8220;511&#8221;] = $a; $all[&#8220;123456&#8221;][&#8220;523&#8221;] = $b; $all[&#8220;123456&#8221;][&#8220;607&#8221;] = $c; var_dump($all); [&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-48750","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48750","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=48750"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/48750\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=48750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=48750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=48750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}