{"id":430,"date":"2021-07-22T18:41:29","date_gmt":"2021-07-22T10:41:29","guid":{"rendered":"https:\/\/wp.dj47.top\/?p=430"},"modified":"2021-10-20T16:06:57","modified_gmt":"2021-10-20T08:06:57","slug":"%e8%bf%94%e5%9b%9ephp%e6%95%b0%e7%bb%84%e4%b8%ad%e6%8c%87%e5%ae%9a%e7%9a%84%e5%a4%9a%e5%88%97","status":"publish","type":"post","link":"https:\/\/www.djlog.cn\/?p=430","title":{"rendered":"\u8fd4\u56dePHP\u6570\u7ec4\u4e2d\u6307\u5b9a\u7684\u591a\u5217"},"content":{"rendered":"<pre class=\"language-php\"><code>&lt;?php\r\nnamespace app\\index\\controller;\r\nclass Temp {\r\n\t\/**\r\n     * \u8fd4\u56de\u6570\u7ec4\u4e2d\u6307\u5b9a\u591a\u5217\r\n     *\r\n     * @param  array  $input       \u9700\u8981\u53d6\u51fa\u6570\u7ec4\u5217\u7684\u591a\u7ef4\u6570\u7ec4\r\n     * @param  String $column_keys \u8981\u53d6\u51fa\u7684\u5217\u540d\uff0c\u9017\u53f7\u5206\u9694\uff0c\u5982\u4e0d\u4f20\u5219\u8fd4\u56de\u6240\u6709\u5217\r\n     * @param  String $index_key   \u4f5c\u4e3a\u8fd4\u56de\u6570\u7ec4\u7684\u7d22\u5f15\u7684\u5217\r\n     * @return array\r\n     *\/\r\n\tpublic function array_columns($input, $column_keys=null, $index_key=null) {\r\n\t\t$result = [];\r\n\t\t$keys =isset($column_keys)? explode(',', $column_keys) : [];\r\n\t\tif($input) {\r\n\t\t\tforeach($input as $k=&gt;$v) {\r\n\t\t\t\t\/\/ \u6307\u5b9a\u8fd4\u56de\u5217\r\n\t\t\t\tif($keys) {\r\n\t\t\t\t\t$tmp = [];\r\n\t\t\t\t\tforeach($keys as $key) {\r\n\t\t\t\t\t\t$tmp[$key] = $v[$key];\r\n\t\t\t\t\t}\r\n\t\t\t\t} else {\r\n\t\t\t\t\t$tmp = $v;\r\n\t\t\t\t}\r\n\t\t\t\t\/\/ \u6307\u5b9a\u7d22\u5f15\u5217\r\n\t\t\t\tif(isset($index_key)) {\r\n\t\t\t\t\t$result[$v[$index_key]] = $tmp;\r\n\t\t\t\t} else {\r\n\t\t\t\t\t$result[] = $tmp;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\treturn $result;\r\n\t}\r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&lt;?php namespace app\\index\\controller; class Temp { \/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[],"class_list":["post-430","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts\/430","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=430"}],"version-history":[{"count":0,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts\/430\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}