title: Get dimensions of 2D array with respect to size of 1D array
body: <p>I have one dimensional array like this </p>
  
  <pre><code>$arr=array('1','2','3','4','5','6','7','8','9','10','11','12','13'......'21');
  </code></pre>
  
  <p>From this i want to create a two dimensional array look like this.</p>
  
  <p><a href="https://i.stack.imgur.com/1nAPR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1nAPR.png" alt="enter image description here"></a></p>
  
  <p>The dimension of the 2D array is depends on the number of elements in the 1D array.</p>
  
  <p><strong>Conditions</strong></p>
  
  <p>1.The number of rows of 2D array is fixed as 5.</p>
  
  <p>2.The number of columns may vary.</p>
  
  <p>3.Third row will be empty except for the last element</p>
  
  <p><strong>NOTE</strong></p>
  
  <p>Size of the one dimensional array is varied.</p>
  
  <p>We need to get the dimension of 2D array also how can i print it?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here is my code</p>
  
  <pre><code>$k=0;
  $l=0;
  $i=0;
  $A=array('1','2','3','4','5','6','7','8','9','10');
  //size of 1D array
  $size=count($arr);
  //2D array
  $B=[];
  $x=?;//no of columns of 2d array
  $y=5;//no of rows of 2d array
  
  for($i=0;$i&lt;$size;$i++){
  
          $B[k][l]=$A[i];
          $k++;
  
          if($k==2 &amp;&amp; $l!=$x){
                  $k++;
  
          }
          if($k==4){
                  $l++;
          }
  
  }
  </code></pre>
  
  <p>How can i get the value of <code>$x</code> it is columns size of 2D array</p>