title: Improve dynamic input fields creation depending array size php
body: <p>I want to create some input fields from an array.
  I have an array like </p>
  
  <pre><code>$info = array("one"   =&gt; "one1",
                "two"   =&gt; "two2",
                "three" =&gt; "three3"
          );
  
  foreach ($info as $key =&gt; $value){
    $field.=  "&lt;div class='formcol form-left middle'&gt;  \n";
    $field.=  "  &lt;input type='text' id='".$key."' size='12' name='".$key."' style='width:".$tam."px;'/&gt;\n";
    $field.=  "\t\t\t   &lt;div class='text'&gt;".$value."&lt;/div&gt;\n";
    $field.=  "\t\t &lt;/div&gt; \n";
  }
  </code></pre>
  
  <p>And it does its job very nice, however If the size of array is 6
  like</p>
  
  <pre><code>$info = array(  "one"   =&gt; "one1",
                 "two"   =&gt; "two2",
                 "three" =&gt; "three3",
                 "four"  =&gt; "four4",
                "five"   =&gt; "five5",
                "six"    =&gt; "six6" 
          );
  </code></pre>
  
  <p>I woul like to change the code I have to create first 3 values of array to create a "div" and then create other "div" with last 3 values, I will have always mod 3 = 0 values, but the problem is to create a new div every 3 used values</p>
  
  <p>How to improve the code? 
  I was thinking something like</p>
  
  <pre><code>$size = sizeof($info);
  
  foreach ($info as $key =&gt; $value){
    //if ($size % 3 ==0)
         $field.=  "&lt;div class='formcol form-left middle'&gt;  \n";
    //else
    //   {
        $field.=  "  &lt;input type='text' id='".$key."' size='12' name='".$key."' style='width:".$tam."px;'/&gt;\n";
        $field.=  "\t\t\t   &lt;div class='text'&gt;".$value."&lt;/div&gt;\n";
    //   }
    //if ($size % 3 ==0) 
        $field.=  "\t\t &lt;/div&gt; \n";
  
  }
  </code></pre>
  
  <p>so for 0,1,2 it is a new div, then for 3,4,5 is new div etc.
  Is it a best aproach to do this?</p>