{"id":602,"date":"2015-07-04T18:13:55","date_gmt":"2015-07-04T09:13:55","guid":{"rendered":"http:\/\/gomocool.net\/gomokulog\/?p=602"},"modified":"2015-07-04T18:13:55","modified_gmt":"2015-07-04T09:13:55","slug":"php-range%e3%81%ae%e4%bd%bf%e3%81%84%e3%81%a9%e3%81%93%e3%82%8d","status":"publish","type":"post","link":"https:\/\/gomokulog.gomocool.net\/?p=602","title":{"rendered":"[PHP] range\u306e\u4f7f\u3044\u3069\u3053\u308d"},"content":{"rendered":"<p>PHP\u306e<strong>range<\/strong>\u3068\u3044\u3046\u95a2\u6570\u304c\u3042\u308b\u3002<\/p>\n<p><span class=\"lang:php decode:true  crayon-inline\">range(0,5);<\/span> \u3068\u66f8\u304f\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u3001<\/p>\n<pre class=\"lang:default decode:true \">array(6) {\r\n  [0]=&gt;  int(0)\r\n  [1]=&gt;  int(1)\r\n  [2]=&gt;  int(2)\r\n  [3]=&gt;  int(3)\r\n  [4]=&gt;  int(4)\r\n  [5]=&gt;  int(5)\r\n}<\/pre>\n<p><span class=\"lang:php decode:true  crayon-inline \">range(a,d);<\/span> \u3068\u66f8\u304f\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \">array(4) {\r\n  [0]=&gt;  string(1) \"a\"\r\n  [1]=&gt;  string(1) \"b\"\r\n  [2]=&gt;  string(1) \"c\"\r\n  [3]=&gt;  string(1) \"d\"\r\n}<\/pre>\n<p>\u3042\u3068\u306f\u3001\u7b2c3\u5f15\u6570\u306bstep\u6570\u3092\u5165\u308c\u3066\u3001\u5076\u6570\u306e\u307f\u3068\u304b\u3001a,c,e\u3068\u304b\u4f5c\u308c\u308b\u3002<\/p>\n<p><span style=\"color: #ff00ff;\">\u3053\u306e\u95a2\u6570\u306e\u4f7f\u3044\u3069\u3053\u308d\u306f\u3001HTML\u306eselect\u6587\u3060\u3068\u601d\u3046\u3002<\/span><br \/>\n(\u300c\u5728\u5eab\u306e\u6570\u5024\u3092\u6301\u3063\u3066\u304d\u3066\u3001\u305d\u3053\u304b\u3089\u6570\u3092\u5f15\u304d\u843d\u3068\u3059\u300d\u3068\u3044\u3063\u305f\u5834\u5408\u306a\u3069)<br \/>\n\u4ee5\u4e0b\u306e\u3088\u3046\u306bforeach\u3067\u56de\u3059\u3002<\/p>\n<pre class=\"lang:php decode:true\">&lt;form&gt;\r\n\t&lt;select name=\"stock\" class=\"form-control col-md-3\"&gt;\r\n\t\t&lt;?php foreach( $items as $item) :?&gt;\r\n\t\t&lt;option value=\"&lt;?=$item?&gt;\"&gt;&lt;?=$item?&gt;&lt;\/option&gt;\r\n\t\t&lt;?php endforeach;?&gt;\r\n\t&lt;\/select&gt;\r\n&lt;\/form&gt;<\/pre>\n<p>\u3055\u3089\u306b\u3001 \u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u3092\u4f7f\u7528\u3057\u3066\u3044\u308b\u5834\u5408\u3001select\u6587\u306e\u4f5c\u6210\u3092\u624b\u52a9\u3051\u3057\u3066\u304f\u308c\u308b\u95a2\u6570\u306b\u306f\u914d\u5217\u3092\u6e21\u3059\u3053\u3068\u304c\u3042\u308b\u3002(\u4ee5\u4e0bCakePHP2\u306e\u4f8b)<\/p>\n<pre class=\"lang:php decode:true\">&lt;form&gt;\r\n\t&lt;?= $this-&gt;Form-&gt;input('Stock',['options'=&gt;$items]);?&gt;\r\n&lt;\/form&gt;<\/pre>\n<p>\u305f\u3060\u3057\u3001 \u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306e\u5834\u5408\u3001<span class=\"lang:php decode:true  crayon-inline\">range(1,5);<\/span> \u3067\u4f5c\u3063\u305f\u914d\u5217\u3092\u5165\u308c\u308b\u3068\u3001<\/p>\n<pre class=\"lang:default decode:true \">&lt;option value=\"0\"&gt;1&lt;\/option&gt;\r\n&lt;option value=\"1\"&gt;2&lt;\/option&gt;\r\n&lt;option value=\"2\"&gt;3&lt;\/option&gt;\r\n&lt;option value=\"3\"&gt;4&lt;\/option&gt;\r\n&lt;option value=\"4\"&gt;5&lt;\/option&gt;<\/pre>\n<p>\u306e\u3088\u3046\u306b\u3001value\u3068\u8868\u793a\u3059\u308b\u5024\u304c\u305a\u308c\u3066\u3057\u307e\u3046\u3002<\/p>\n<p>\u305d\u306e\u5834\u5408\u3001array_combine\u3092\u4f7f\u3063\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u3059\u308b\u3002<\/p>\n<pre class=\"lang:php decode:true \">$items = array_combine(range(1,5),range(1,5))<\/pre>\n<p>\u3055\u3089\u306b\u3001\u305d\u3053\u307e\u3067\u3059\u308b\u5fc5\u8981\u306f\u7121\u3044\u304b\u3082\u3060\u304c\u3001array_map\u3068sprintf\u306a\u3069\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u3001<\/p>\n<pre class=\"lang:php decode:true \">$items_age = array_map(function($val) {\r\n\treturn sprintf('%d\u500b', $val);\r\n}, range(1, 5));\r\n$items = array_combine(range(1, 5), $items_age);<\/pre>\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u51fa\u3059\u3053\u3068\u3082\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"lang:default decode:true \">array(\r\n\t(int) 1 =&gt; '1\u500b',\r\n\t(int) 2 =&gt; '2\u500b',\r\n\t(int) 3 =&gt; '3\u500b',\r\n\t(int) 4 =&gt; '4\u500b',\r\n\t(int) 5 =&gt; '5\u500b'\r\n)<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP\u306erange\u3068\u3044\u3046\u95a2\u6570\u304c\u3042\u308b\u3002 range(0,5); \u3068\u66f8\u304f\u3068\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u3001 array(6) { [0]=&gt; int(0) [1]=&gt; int(1) [2]=&gt; int(2) [3]=&#038;&hellip;  <a href=\"https:\/\/gomokulog.gomocool.net\/?p=602\" class=\"more-link\">more <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[54],"class_list":["post-602","post","type-post","status-publish","format-standard","hentry","category-php","tag-range"],"_links":{"self":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=602"}],"version-history":[{"count":1,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/602\/revisions"}],"predecessor-version":[{"id":603,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/602\/revisions\/603"}],"wp:attachment":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}