{"id":6318,"date":"2018-04-19T10:00:02","date_gmt":"2018-04-19T01:00:02","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=6318"},"modified":"2018-04-19T11:00:44","modified_gmt":"2018-04-19T02:00:44","slug":"php%e7%a0%94%e4%bf%ae-each%e9%96%a2%e6%95%b0%e3%81%a8%e9%85%8d%e5%88%97%e3%81%ae%e5%8f%af%e5%a4%89%e5%a4%89%e6%95%b0%e3%81%aephp7-2%e5%af%be%e5%bf%9c","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/6318","title":{"rendered":"PHP\u7814\u4fee each()\u95a2\u6570\u3068\u914d\u5217\u306e\u53ef\u5909\u5909\u6570\u306ePHP7.2\u5bfe\u5fdc"},"content":{"rendered":"<p>\u00a0PHP\u7814\u4fee\u4e2d\u306eyoshimoto\u3067\u3059\u3002<br \/>\n \u672c\u65e5\u306f\u3001\u7814\u4fee\u4e2d\u3067\u304a\u3053\u306a\u3063\u305f\u4ee5\u4e0b\u306ePHP\uff17\u5bfe\u5fdc\u3092\u3054\u7d39\u4ecb\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3059\u3002<\/p>\n<p>* each() \u95a2\u6570\u306ePHP7\u5bfe\u5fdc<br \/>\n * \u914d\u5217\u306e\u53ef\u5909\u5909\u6570\u306ePHP7\u5bfe\u5fdc<\/p>\n<p><!--more--><\/p>\n<h3>each()\u95a2\u6570\u306ePHP\uff17\u5bfe\u5fdc<\/h3>\n<p><a href=\"http:\/\/php.net\/manual\/ja\/function.each.php\">each()\u95a2\u6570<\/a>\u306f\u3001\u914d\u5217\u306e\u5185\u90e8\u30dd\u30a4\u30f3\u30bf\u30fc\u3092\u9806\u6b21\u9032\u3081\u3066\u304f\u308c\u308b\u5927\u5909\u4fbf\u5229\u306a\u95a2\u6570\u3067\u3059\u304c\u3001<br \/>\n PHP7.2\u304b\u3089\u975e\u63a8\u5968\u3068\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<\/p>\n<p> \u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8907\u6570\u306e\u914d\u5217\u3092\u540c\u6642\u306b\u9032\u884c\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<table style=\"height: 111px;width: 464px\">\n<tbody>\n<tr style=\"height: 33.4375px\">\n<td style=\"width: 464px;height: 33.4375px\">\n<p>$num = 3;<br \/>\n $names = [&#8216;apple&#8217;, &#8216;banana&#8217;, &#8216;orange&#8217;];<br \/>\n $prices = [100, 150, 80];<\/p>\n<p>for ($i = 0; $i &lt;$ num; $i++) {<br \/>\n <strong>\u00a0 \u00a0 $name = each($names);<\/strong><br \/>\n <strong> \u00a0 \u00a0 $price = each($prices);<\/strong><br \/>\n \u00a0 \u00a0 $items[$name[&#8220;value&#8221;]] = $price[&#8220;value&#8221;]<br \/>\n }<\/p>\n<p>print_r($items);<br \/>\n \/* \u7d50\u679c<br \/>\n Array<br \/>\n (<br \/>\n \u00a0 \u00a0 [apple] =&gt; 100<br \/>\n \u00a0 \u00a0 [banana] =&gt; 150<br \/>\n \u00a0 \u00a0 [orange] =&gt; 80<br \/>\n )<br \/>\n *\/<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>PHP7.2\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306bcurrent()\u95a2\u6570\u3067\u8981\u7d20\u3092\u53d6\u308a\u51fa\u3057\u3001<br \/>\n next()\u95a2\u6570\u3067\u6b21\u306e\u8981\u7d20\u306b\u9032\u3080\u3088\u3046\u306b\u3055\u305b\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<table style=\"height: 111px;width: 464px\">\n<tbody>\n<tr style=\"height: 33.4375px\">\n<td style=\"width: 464px;height: 33.4375px\">\n<p>$num = 3;<br \/>\n $names = [&#8216;apple&#8217;, &#8216;banana&#8217;, &#8216;orange&#8217;];<br \/>\n $prices = [100, 150, 80];<\/p>\n<p>for ($i = 0; $i &lt;$ num; $i++) {<br \/>\n <strong>\u00a0 \u00a0 $name = current($names); next($names);<\/strong><br \/>\n <strong>\u00a0 \u00a0 $price = current($prices); next(prices);<\/strong><br \/>\n \u00a0 \u00a0 $items[$name] = $price<br \/>\n }<\/p>\n<p>print_r($items);<br \/>\n \/* \u7d50\u679c<br \/>\n Array<br \/>\n (<br \/>\n \u00a0 \u00a0 [apple] =&gt; 100<br \/>\n \u00a0 \u00a0 [banana] =&gt; 150<br \/>\n \u00a0 \u00a0 [orange] =&gt; 80<br \/>\n )<br \/>\n *\/<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u308f\u3056\u308f\u3056\u8a18\u8ff0\u91cf\u304c\u591a\u304f\u306a\u308b\u65b9\u5411\u3067\u30d0\u30fc\u30b8\u30e7\u30f3\u30a2\u30c3\u30d7\u3055\u308c\u3066\u3057\u307e\u3046\u306e\u306f\u3001<br \/>\n \u3061\u3087\u3063\u3068\u7d0d\u5f97\u304c\u3044\u304d\u307e\u305b\u3093\u304c\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306b\u4ee3\u66ff\u3059\u308b\u95a2\u6570\u304c\u3042\u308b\u3053\u3068\u306a\u3069\u3067\u5ec3\u6b62\u3055\u308c\u305f\u3088\u3046\u3067\u3059\u3002<\/p>\n<h3>\n \u914d\u5217\u306e\u53ef\u5909\u5909\u6570\u306ePHP\uff17\u5bfe\u5fdc<\/h3>\n<p>\u914d\u5217\u306e\u53ef\u5909\u5909\u6570\u306e\u89e3\u6790\u65b9\u6cd5\u304cPHP5\u3068PHP7\u3067\u5909\u66f4\u3055\u308c\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u3002<br \/>\n \u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u306fPHP5\u3067\u306f\u3001\u4f55\u306e\u554f\u984c\u3082\u306a\u304f\u52d5\u4f5c\u3044\u305f\u3057\u307e\u3059\u3002<\/p>\n<table style=\"height: 111px;width: 475px\">\n<tbody>\n<tr style=\"height: 0.875px\">\n<td style=\"width: 477px;height: 0.875px\">\n<p>$variables = [&#8216;foo&#8217;, &#8216;bar&#8217;];<br \/>\n $$variables[0] = &#8216;Hi foo&#8217;; \/\/ $foo = &#8216;Hi foo&#8217;;\u00a0<br \/>\n $$variables[1] = &#8216;Hi bar&#8217;; \/\/ $bar = &#8216;Hi bar&#8217;;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u3057\u304b\u3057\u306a\u304c\u3089PHP7\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30a8\u30e9\u30fc\u304c\u51fa\u529b\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<table style=\"height: 77px;width: 400px\">\n<tbody>\n<tr style=\"height: 10.875px\">\n<td style=\"width: 390px;height: 10.875px\">\n<p><strong>PHP Notice:\u00a0 Array to string conversion<br \/>\n Notice: Undefined variable: foo<br \/>\n <\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\uff11\u884c\u76ee\u306e\u30a8\u30e9\u30fc\u306f\u3001\u914d\u5217\u3092\u6587\u5b57\u5217\u3068\u3057\u3066\u8a55\u4fa1\u3057\u3066\u3057\u307e\u3063\u305f\u969b\u306b\u51fa\u529b\u3055\u308c\u308b\u30a8\u30e9\u30fc\u3068\u540c\u4e00\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u3053\u3061\u3089\u306f\u3001PHP7\u3067\u306f\u7d14\u7c8b\u306b\u5de6\u304b\u3089\u53f3\u3078\u3068\u8a55\u4fa1\u3059\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u3001<br \/>\n \u4ee5\u4e0b\u306e\u3088\u3046\u306b\u89e3\u6790\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u3057\u307e\u3063\u305f\u305f\u3081\u3067\u3059\u3002<\/p>\n<p>$ \u2192\u00a0<strong>$variables \u2192\u00a0<\/strong>[0]<\/p>\n<p>\u771f\u3093\u4e2d\u306e<strong>$variables<\/strong>\u5909\u6570\u3092PHP\u304c\u8a55\u4fa1\u3057\u305f\u969b\u306b\u5185\u90e8\u306e\u5024(\u914d\u5217)\u3092\u6587\u5b57\u5217(\u4e00\u756a\u5de6\u306e$\u306b\u304f\u3063\u3064\u3051\u308b\u305f\u3081\u306e\u5909\u6570\u540d\uff09\u306b\u5909\u63db\u3057\u3088\u3046\u3068\u3057\u3066\u3057\u307e\u3044\u3001\u30a8\u30e9\u30fc\u304c\u51fa\u529b\u3055\u308c\u305f\u3068\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n<p>\u5f93\u3063\u3066PHP7\u3067\u306f\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b{}\u3092\u3064\u3051\u3066\u5148\u306b\u8a55\u4fa1\u3055\u308c\u308b\u3088\u3046\u306b\u4fee\u6b63\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<table style=\"height: 111px;width: 464px\">\n<tbody>\n<tr style=\"height: 26.875px\">\n<td style=\"width: 464px;height: 26.875px\">\n<p>$variables = [&#8216;foo&#8217;, &#8216;bar&#8217;];<br \/>\n ${$variables[0]} = &#8216;Hi foo&#8217;; \/\/ $foo = &#8216;Hi foo&#8217;;\u00a0<br \/>\n ${$variables[1] }= &#8216;Hi bar&#8217;; \/\/ $bar = &#8216;Hi bar&#8217;;<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u307e\u3068\u3081<\/h3>\n<p>PHP7\u3067\u306f\u3001\u51e6\u7406\u901f\u5ea6\u304c\u5927\u5e45\u306b\u6539\u5584\u3055\u308c\u308b\u3060\u3051\u3067\u306a\u304f\u3001<br \/>\n \u95a2\u6570\u306b\u578b\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u3001\u5b89\u5168\u6027\u3082\u9ad8\u304f\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>\u3067\u3059\u304c\u3001\u4e0a\u8a18\u306e\u3088\u3046\u306bPHP5\u3068PHP7\u3067\u306f\u4e92\u63db\u6027\u304c\u7121\u3044\u6a5f\u80fd\u304c\u6ca2\u5c71\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u4e0a\u3001PHP7\u5bfe\u5fdc\u306e\u3054\u7d39\u4ecb\u3067\u3057\u305f\u3002<\/p>\n<p>\u6728\u66dc\u62c5\u5f53 yoshimoto<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/6318\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/6318\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"PHP\u7814\u4fee each()\u95a2\u6570\u3068\u914d\u5217\u306e\u53ef\u5909\u5909\u6570\u306ePHP7.2\u5bfe\u5fdc\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/6318\" data-text=\"PHP\u7814\u4fee each()\u95a2\u6570\u3068\u914d\u5217\u306e\u53ef\u5909\u5909\u6570\u306ePHP7.2\u5bfe\u5fdc\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/6318\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/6318\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0PHP\u7814\u4fee\u4e2d\u306eyoshimoto\u3067\u3059\u3002 \u672c\u65e5\u306f\u3001\u7814\u4fee\u4e2d\u3067\u304a\u3053\u306a\u3063\u305f\u4ee5\u4e0b\u306ePHP\uff17\u5bfe\u5fdc\u3092\u3054\u7d39\u4ecb\u3055\u305b\u3066\u3044\u305f\u3060\u304d\u307e\u3059\u3002 * each() \u95a2\u6570\u306ePHP7\u5bfe\u5fdc * \u914d\u5217\u306e\u53ef\u5909\u5909\u6570\u306ePHP7\u5bfe\u5fdc<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/6318"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=6318"}],"version-history":[{"count":35,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/6318\/revisions"}],"predecessor-version":[{"id":6355,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/6318\/revisions\/6355"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=6318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=6318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=6318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}