{"id":536,"date":"2019-07-26T17:29:12","date_gmt":"2019-07-26T08:29:12","guid":{"rendered":"https:\/\/took.jp\/?p=536"},"modified":"2020-06-15T15:47:27","modified_gmt":"2020-06-15T06:47:27","slug":"post-536","status":"publish","type":"post","link":"https:\/\/took.jp\/tech-blog\/post-536\/","title":{"rendered":"for\u6587\u3068foreach\u6587\u3069\u3063\u3061\u304c\u3044\u3044\u306e\uff1f\u51e6\u7406\u901f\u5ea6\u3092\u6bd4\u8f03\u3057\u3066\u307f\u308b"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p>\u6700\u8fd1\u306f\u51e6\u7406\u901f\u5ea6\u3092\u6e2c\u308b\u306e\u304c\u5c11\u3057\u30d6\u30fc\u30e0\u3067\u3059\u7b11<\/p>\n<p>\u4eca\u56de\u306f\u3001for\u3068foreach\u306e\u51e6\u7406\u901f\u5ea6\u3092\u8a08\u6e2c\u3057\u3001\u6bd4\u8f03\u3092\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u30cd\u30c3\u30c8\u3067\u51e6\u7406\u901f\u5ea6\u306e\u6bd4\u8f03\u3092\u691c\u7d22\u3057\u3066\u307f\u308b\u3068\u3001\u3069\u3046\u3084\u3089<strong>foreach\u306e\u304c\u512a\u79c0<\/strong>\u3068\u306e\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u4ee5\u524d\u5148\u8f29\u306b\u30b3\u30fc\u30c9\u30ec\u30d3\u30e5\u30fc\u3057\u3066\u3082\u3089\u3063\u305f\u3068\u304d\u306b\u306f\u3001<\/p>\n<p>\u300c foreach\u3067\u51e6\u7406\u66f8\u3044\u3066\u308b\u3051\u3069\u3001for\u306e\u65b9\u304c\u51e6\u7406\u65e9\u3044\u304b\u3089\u3001\u30ad\u30fc\u3092\u4f7f\u7528\u3057\u306a\u3044\u90e8\u5206\u306b\u3064\u3044\u3066\u306f\u3001for\u6587\u3092\u4f7f\u7528\u3057\u3066\u3002\u300d<\/p>\n<p>\u3068\u8a00\u308f\u308c\u305f\u3053\u3068\u3082\u3042\u308a\u3001\u5c11\u3057\u6df7\u4e71\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u81ea\u8eab\u3067\u8a08\u6e2c\u3057\u3001\u78ba\u304b\u3081\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u691c\u8a3c\u65b9\u6cd5<\/h2>\n<p>\u8a00\u8a9e\u306fPHP\u3092\u4f7f\u7528\u3057\u3001\u4ee5\u4e0b\u306e\u8a18\u4e8b\u3092\u53c2\u8003\u306b\u3057\u3001\u51e6\u7406\u901f\u5ea6\u3092\u8a08\u6e2c\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/qiita.com\/ao_love\/items\/a2d8b8566d0426195002\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/qiita.com\/ao_love\/items\/a2d8b8566d0426195002<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<p><strong>for\u6587\u306e\u51e6\u7406\u901f\u5ea6\u3092\u53d6\u5f97<\/strong><\/p>\n<pre class=\"line-numbers\"><code class=\"language-php\">\/\/\u914d\u5217\u306e\u4f5c\u6210\r\n$array = array();\r\nfor($i=1;$i&lt;=100000;$i++){\r\n    $array[] = $i;\r\n}\r\n$time_start = microtime(true);\r\n\r\n\/\/ \u8a08\u6e2c\u958b\u59cb\r\nfor($i=1;$i&lt;count($array);$i++){\r\n    echo $i;\r\n    echo '&lt;br&gt;';\r\n}\r\n\/\/\u8a08\u6e2c\u7d42\u4e86\r\n\r\n$time = microtime(true) - $time_start;\r\necho \"{$time} \u79d2\";<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>foreach\u306e\u51e6\u7406\u901f\u5ea6\u3092\u53d6\u5f97<\/strong><\/p>\n<pre class=\"line-numbers\"><code class=\"language-php\">\/\/\u914d\u5217\u306e\u4f5c\u6210\r\n$array = array();\r\nfor($i=1;$i&lt;=100000;$i++){\r\n    $array[] = $i;\r\n}\r\n$time_start = microtime(true);\r\n\r\n\/\/ \u8a08\u6e2c\u958b\u59cb\r\nforeach($array as $value){\r\n    echo $value;\r\n    echo '&lt;br&gt;';\r\n}\r\n\/\/\u8a08\u6e2c\u7d42\u4e86\r\n\r\n$time = microtime(true) - $time_start;\r\necho \"{$time} \u79d2\";<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>\u51e6\u7406\u306e\u6d41\u308c\u306f\u4e21\u65b9\u3068\u3082\u540c\u3058\u3067\u3059\u3002<\/p>\n<p>\u307e\u305a\u3001\u6570\u5b57\u304c1\u304b\u3089\u9806\u306b10\u4e07\u307e\u3067\u3092\u5024\u3068\u3057\u305f\u914d\u5217\u3092\u751f\u6210\u3057\u307e\u3059\u3002\uff08\u8a08\u6e2c\u6642\u9593\u306b\u306f\u542b\u307f\u307e\u305b\u3093\uff09<\/p>\n<p>\u305d\u306e\u5f8c\u3001for\u307e\u305f\u306fforeach\u3067\u914d\u5217\u306e\u5024\u3092\u9806\u756a\u306b\u53d6\u5f97\u3057\u3001echo\u3067\u51fa\u529b\u3057\u307e\u3059\u3002<\/p>\n<p>\u5168\u3066\u306e\u51e6\u7406\u304c\u7d42\u4e86\u3057\u305f\u3089\u3001\u304b\u304b\u3063\u305f\u6642\u9593\u3092\u51fa\u529b\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u307e\u305f\u30011\u56de\u306e\u6e2c\u5b9a\u7d50\u679c\u306e\u307f\u3060\u3068\u6b63\u3057\u3044\u7d50\u679c\u304c\u5f97\u3089\u308c\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308b\u305f\u3081\u3001<span style=\"text-decoration: underline;\">\uff15\u56de\u6e2c\u5b9a\u3092\u884c\u3044\u3001\u5e73\u5747\u6642\u9593\u3001\u5408\u8a08\u6642\u9593<\/span>\u3092\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p>&nbsp;<\/p>\n<h2>\u6e2c\u5b9a\u7d50\u679c<\/h2>\n<p><strong>for\u6587\u306e\u51e6\u7406\u901f\u5ea6\u3092\u53d6\u5f97<\/strong><\/p>\n<p>1\u56de\u76ee\uff1a\u30000.076268196105957 \u79d2<br \/>\n2\u56de\u76ee\uff1a\u30000.088988065719604 \u79d2<br \/>\n3\u56de\u76ee\uff1a\u30000.08555006980896 \u79d2<br \/>\n4\u56de\u76ee\uff1a\u30000.082581996917725 \u79d2<br \/>\n5\u56de\u76ee\uff1a\u30000.085355043411255 \u79d2<\/p>\n<p>\u5e73\u5747\uff1a\u30000.418743371963501\u79d2<br \/>\n\u5408\u8a08\uff1a\u30000.0837486743927002\u79d2<\/p>\n<p>&nbsp;<\/p>\n<p><strong>foreach\u306e\u51e6\u7406\u901f\u5ea6\u3092\u53d6\u5f97<\/strong><\/p>\n<p>0.068567037582397 \u79d2<br \/>\n0.061532020568848 \u79d2<br \/>\n0.063639879226685 \u79d2<br \/>\n0.061524152755737 \u79d2<br \/>\n0.064805030822754 \u79d2<\/p>\n<p>\u5e73\u5747\u30000.320068120956421\u79d2<br \/>\n\u5408\u8a08\u30000.0640136241912842\u79d2<\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u5e73\u5747\u3000<\/strong>0.019735050201416\u79d2\u306e\u5dee\u3000\uff1d\u3000<strong>\u7d040.02\u79d2\u306e\u5dee<\/strong><br \/>\n<strong>\u5408\u8a08<\/strong>\u30000.09867525100708\u79d2\u306e\u5dee\u00a0 \u3000\uff1d\u3000<strong>\u7d040.1\u79d2\u306e\u5dee<\/strong><br \/>\n\u304c\u3067\u307e\u3057\u305f\u3002<\/p>\n<p>\u3084\u306f\u308a\u30cd\u30c3\u30c8\u3067\u66f8\u3044\u3066\u3042\u308b\u901a\u308a\u3001foreach\u306e\u304c\u512a\u79c0\u306a\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u306f\u3001\u3042\u306e\u5148\u8f29\u3001\u5618\u3064\u304d\u3084\u304c\u3063\u305f\u306e\u306a...<\/p>\n<p>&nbsp;<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u30eb\u30fc\u30d7\u51e6\u7406\u306f\u3001\u53ef\u8aad\u6027\u306b\u3082\u512a\u308c\u3066\u304a\u308a\u3001\u51e6\u7406\u901f\u5ea6\u3082\u901f\u3044foreach\u3092\u4f7f\u7528\u3059\u308b\u3079\u304d\uff01<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u6700\u8fd1\u306f\u51e6\u7406\u901f\u5ea6\u3092\u6e2c\u308b\u306e\u304c\u5c11\u3057\u30d6\u30fc\u30e0\u3067\u3059\u7b11 \u4eca\u56de\u306f\u3001for\u3068foreach\u306e\u51e6\u7406\u901f\u5ea6\u3092\u8a08\u6e2c\u3057\u3001\u6bd4\u8f03\u3092\u3057\u307e\u3059\u3002 &nbsp; \u30cd\u30c3\u30c8\u3067\u51e6\u7406\u901f\u5ea6\u306e\u6bd4\u8f03\u3092\u691c\u7d22\u3057\u3066\u307f\u308b\u3068\u3001\u3069\u3046\u3084\u3089foreach\u306e\u304c\u512a\u79c0\u3068\u306e\u3053\u3068\u3067\u3059\u3002 \u3057\u304b\u3057\u3001\u4ee5\u524d\u5148\u8f29\u306b\u2026<\/p>\n","protected":false},"author":3,"featured_media":1966,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62,68],"tags":[],"class_list":["post-536","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-it","category-68"],"_links":{"self":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts\/536","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/comments?post=536"}],"version-history":[{"count":0,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/posts\/536\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/media\/1966"}],"wp:attachment":[{"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/media?parent=536"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/categories?post=536"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/took.jp\/tech-blog\/wp-json\/wp\/v2\/tags?post=536"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}