{"id":2539,"date":"2019-10-27T22:34:06","date_gmt":"2019-10-27T13:34:06","guid":{"rendered":"https:\/\/katblog.manadream.net\/?p=2539"},"modified":"2019-11-04T16:04:10","modified_gmt":"2019-11-04T07:04:10","slug":"php-array-key-reset","status":"publish","type":"post","link":"https:\/\/katblog.manadream.net\/index.php\/2019\/10\/27\/php-array-key-reset\/","title":{"rendered":"\u3010PHP\u3011\u9023\u60f3\u914d\u5217\u306e\u6570\u5024\u30ad\u30fc\u306e\u307f\u3092\u30ea\u30bb\u30c3\u30c8\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>\u3069\u3046\u3082\u3001kat\u3067\u3059\u3002<\/p>\n<p>\u4eca\u56de\u306fPHP\u306e\u9023\u60f3\u914d\u5217\u306b\u3064\u3044\u3066\u306e\u8a18\u4e8b\u306b\u306a\u308a\u307e\u3059\uff01<\/p>\n<p><strong>\u691c\u7d22\u3057\u3066\u3082\u610f\u5916\u3068\u89e3\u6c7a\u7b56\u304c\u51fa\u3066\u3053\u306a\u304b\u3063\u305f<\/strong>\u306e\u3067\u4eca\u56de\u306e\u8a18\u4e8b\u3092\u66f8\u304d\u307e\u3057\u305f\uff01<\/p>\n\n\n<h2 class=\"wp-block-heading\">\u3084\u308a\u305f\u3044\u3053\u3068<\/h2>\n\n\n<p>\u4eca\u56de\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5909\u63db\u3092\u884c\u3046\u3053\u3068\u304c\u76ee\u7684\u3067\u3059\u3002<\/p>\n<p>\u2605\u5909\u63db\u524d<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nArray\n(\n    &#x5B;5] =&gt; Array\n        (\n            &#x5B;name] =&gt; \u7530\u4e2d\u3000\u592a\u90ce\n            &#x5B;favoriteFoods] =&gt; Array\n                (\n                    &#x5B;4] =&gt; \u307f\u304b\u3093\n                    &#x5B;1] =&gt; \u305f\u3053\u3084\u304d\n                    &#x5B;6] =&gt; \u5375\u713c\u304d\n                )\n            &#x5B;age] =&gt; 16\u624d\n        )\n    &#x5B;2] =&gt; Array\n        (\n            &#x5B;name] =&gt; \u7530\u4e2d\u3000\u82b1\u5b50\n            &#x5B;favoriteFoods] =&gt; Array\n                (\n                    &#x5B;7] =&gt; \u308a\u3093\u3054\n                    &#x5B;5] =&gt; \u30d0\u30ca\u30ca\n                    &#x5B;2] =&gt; \u30db\u30c3\u30c8\u30b1\u30fc\u30ad\n                )\n            &#x5B;age] =&gt; 15\u624d\n        )\n    &#x5B;7] =&gt; Array\n        (\n            &#x5B;name] =&gt; \u7530\u4e2d\u3000\u4e8c\u90ce\n            &#x5B;favoriteFoods] =&gt; Array\n                (\n                    &#x5B;9] =&gt; \u3044\u3061\u3054\n                    &#x5B;8] =&gt; \u30e9\u30fc\u30e1\u30f3\n                )\n            &#x5B;age] =&gt; 12\u624d\n        )\n)\n<\/pre><\/div>\n\n<p>\u2605\u5909\u63db\u5f8c<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\nArray\n(\n    &#x5B;0] =&gt; Array\n        (\n            &#x5B;name] =&gt; \u7530\u4e2d\u3000\u592a\u90ce\n            &#x5B;favoriteFoods] =&gt; Array\n                (\n                    &#x5B;0] =&gt; \u307f\u304b\u3093\n                    &#x5B;1] =&gt; \u305f\u3053\u3084\u304d\n                    &#x5B;2] =&gt; \u5375\u713c\u304d\n                )\n            &#x5B;age] =&gt; 16\u624d\n        )\n    &#x5B;1] =&gt; Array\n        (\n            &#x5B;name] =&gt; \u7530\u4e2d\u3000\u82b1\u5b50\n            &#x5B;favoriteFoods] =&gt; Array\n                (\n                    &#x5B;0] =&gt; \u308a\u3093\u3054\n                    &#x5B;1] =&gt; \u30d0\u30ca\u30ca\n                    &#x5B;2] =&gt; \u30db\u30c3\u30c8\u30b1\u30fc\u30ad\n                )\n            &#x5B;age] =&gt; 15\u624d\n        )\n    &#x5B;2] =&gt; Array\n        (\n            &#x5B;name] =&gt; \u7530\u4e2d\u3000\u4e8c\u90ce\n            &#x5B;favoriteFoods] =&gt; Array\n                (\n                    &#x5B;0] =&gt; \u3044\u3061\u3054\n                    &#x5B;1] =&gt; \u30e9\u30fc\u30e1\u30f3\n                )\n            &#x5B;age] =&gt; 12\u624d\n        )\n)\n<\/pre><\/div>\n\n<p>\u898b\u3066\u304a\u5206\u304b\u308a\u306e\u901a\u308a\u300c\u6570\u5b57\u306e\u30ad\u30fc\u300d\u306e\u307f\u304c0\u304b\u3089\u306e\u63a1\u756a\u306b\u30ea\u30bb\u30c3\u30c8\u3057\u305f\u3044\u3068\u3044\u3046\u306e\u304c\u4eca\u56de\u3084\u308a\u305f\u3044\u3053\u3068\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">\u6570\u5b57\u30ad\u30fc\u306e\u307f\u30ea\u30bb\u30c3\u30c8\u3059\u308b\u65b9\u6cd5<\/h2>\n\n\n<p>\u305d\u308c\u3067\u306f\u5b9f\u969b\u306b\u30ea\u30bb\u30c3\u30c8\u3059\u308b\u65b9\u6cd5\u3067\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u95a2\u6570\u3092\u4f5c\u6210\u3059\u308b\u3053\u3068\u3067\u30ea\u30bb\u30c3\u30c8\u304c\u53ef\u80fd\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; title: ; notranslate\" title=\"\">\n\/**\n* \u914d\u5217\u306e\u6570\u5024\u30ad\u30fc\u3092\u30ea\u30bb\u30c3\u30c8\u3059\u308b\n* @param array $array \u914d\u5217\n* @return array \u30ea\u30bb\u30c3\u30c8\u5f8c\u306e\u914d\u5217\n*\/\nfunction resetKeys($array) {\n\n    if (!is_array($array) || empty($array)) {\n        return $array;\n    }\n\n    $firstKey = key(array_slice($array, 0, 1));\n\n    \/\/ \u914d\u5217\u306e\u4e00\u3064\u76ee\u306e\u30ad\u30fc\u304c\u6570\u5024\u306e\u5834\u5408\u306e\u307f\u30ea\u30bb\u30c3\u30c8\u3059\u308b\n    if (is_numeric($firstKey)) {\n        $array = array_values($array);\n    }\n\n    foreach ($array as $key =&gt; $val) {\n        if (is_array($val)) {\n            \/\/ \u518d\u8d77\n            $array&#x5B;$key] = resetKeys($val);\n        }\n    }\n\n    return $array;\n}\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u3044\u65b9<\/h3>\n\n\n<p>\u4f7f\u3046\u3068\u304d\u306f\u5f15\u6570\u306b\u30ad\u30fc\u3092\u30ea\u30bb\u30c3\u30c8\u3057\u305f\u3044\u914d\u5217\u3092\u6e21\u3059\u3060\u3051\u3067\u3059\u3002<\/p>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: php; highlight: [1]; title: ; notranslate\" title=\"\">\n$array = resetKeys($array);  \/\/ $array\u304c\u30ea\u30bb\u30c3\u30c8\u3057\u305f\u3044\u914d\u5217\n\nvar_dump($array); \/\/ \u30ea\u30bb\u30c3\u30c8\u5f8c\u306e\u5185\u5bb9\u3092\u753b\u9762\u306b\u8868\u793a\u3057\u307e\u3059\u3002\uff08\u78ba\u8a8d\u7528\uff09\n<\/pre><\/div>\n\n<p>\u7c21\u5358\u3067\u3059\u306d\uff01<\/p>\n\n\n<h2 class=\"wp-block-heading\">\u6700\u5f8c\u306b<\/h2>\n\n\n<p>\u3044\u304b\u304c\u3067\u3057\u305f\u304b\uff1f<\/p>\n<p>PHP\u306e\u6a19\u6e96\u95a2\u6570\u306b\u3042\u308a\u305d\u3046\u3067\u610f\u5916\u3068\u306a\u304f\u3001\u691c\u7d22\u3057\u3066\u3082\u306a\u304b\u306a\u304b\u6b63\u3057\u3044\u60c5\u5831\u306b\u51fa\u4f1a\u3048\u306a\u304b\u3063\u305f\u305f\u3081\u5099\u5fd8\u9332\u306e\u610f\u5473\u3082\u8fbc\u3081\u3066\u66f8\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u540c\u3058\u3088\u3046\u306b\u56f0\u3063\u3066\u3044\u308b\u65b9\u306e\u5c11\u3057\u3067\u3082\u52a9\u3051\u306b\u306a\u308c\u3070\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0a\u3001PHP\u306e\u9023\u60f3\u914d\u5217\u306e\u6570\u5024\u30ad\u30fc\u306e\u307f\u3092\u30ea\u30bb\u30c3\u30c8\u3059\u308b\u65b9\u6cd5\u3067\u3057\u305f\u301c\u3002<\/p>","protected":false},"excerpt":{"rendered":"<p>\u3069\u3046\u3082\u3001kat\u3067\u3059\u3002 \u4eca\u56de\u306fPHP\u306e\u9023\u60f3\u914d\u5217\u306b\u3064\u3044\u3066\u306e\u8a18\u4e8b\u306b\u306a\u308a\u307e\u3059\uff01 \u691c\u7d22\u3057\u3066\u3082\u610f\u5916\u3068\u89e3\u6c7a\u7b56\u304c\u51fa\u3066\u3053\u306a\u304b\u3063\u305f\u306e\u3067\u4eca\u56de\u306e\u8a18\u4e8b\u3092\u66f8\u304d\u307e\u3057\u305f\uff01 \u3084\u308a\u305f\u3044\u3053\u3068 \u4eca\u56de\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5909\u63db\u3092\u884c\u3046\u3053\u3068\u304c\u76ee\u7684\u3067\u3059\u3002 \u2605\u5909\u63db\u524d \u2605\u5909\u63db\u5f8c<\/p>\n","protected":false},"author":1,"featured_media":2656,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_locale":"","_original_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[25,2],"tags":[36,82,44,83],"class_list":["post-2539","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php","category-programing","tag-php","tag-82","tag-44","tag-83","ja"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/katblog.manadream.net\/wp-content\/uploads\/2019\/10\/php-array-key-reset.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paUgnN-EX","_links":{"self":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/2539"}],"collection":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/comments?post=2539"}],"version-history":[{"count":19,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/2539\/revisions"}],"predecessor-version":[{"id":2684,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/posts\/2539\/revisions\/2684"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/media\/2656"}],"wp:attachment":[{"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/media?parent=2539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/categories?post=2539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/katblog.manadream.net\/index.php\/wp-json\/wp\/v2\/tags?post=2539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}