title: how to split a 2D array into array chunks on the basis of a index value in PHP
body: <p>I have a 2D-array which contains product id, product name and company id, now i want to make group of company having product information and can mail to company with product details, i have data in array like</p>
  
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [id] =&gt; 5363
          [proname] =&gt; pro1
          [company_id] =&gt; 101
      )
  
  [1] =&gt; Array
      (
          [id] =&gt; 5364
          [proname] =&gt; pro2
          [company_id] =&gt; 105
      )
  
  [2] =&gt; Array
      (
          [id] =&gt; 5366
          [proname] =&gt; pro3
          [company_id] =&gt; 102
      )
  
  [3] =&gt; Array
      (
          [id] =&gt; 5367
          [proname] =&gt; pro4
          [company_id] =&gt; 101
      )
  
  [4] =&gt; Array
      (
          [id] =&gt; 5368
          [proname] =&gt; pro5
          [company_id] =&gt; 105
      )
  
  [5] =&gt; Array
      (
          [id] =&gt; 5369
          [proname] =&gt; pro6
          [company_id] =&gt; 105
      )
  
  [6] =&gt; Array
      (
          [id] =&gt; 3847
          [proname] =&gt; pro7
          [company_id] =&gt; 102
      )
  
  [7] =&gt; Array
      (
          [id] =&gt; 3849
          [proname] =&gt; pro8
          [company_id] =&gt; 105
      )
  
  [8] =&gt; Array
      (
          [id] =&gt; 5371
          [proname] =&gt; pro9
          [company_id] =&gt; 101
      )
  
  [9] =&gt; Array
      (
          [id] =&gt; 5383
          [proname] =&gt; pro10
          [company_id] =&gt; 102
      )
  
  [10] =&gt; Array
      (
          [id] =&gt; 5385
          [proname] =&gt; pro11
          [company_id] =&gt; 105
      )
  
  )
  </code></pre>
  
  <p>And i want to make array chunks on the basis of company_id thus final array should be 3-d array and output should like this</p>
  
  <pre><code>array(
  
     [0]=&gt;Array(
          [0] =&gt; Array
              (
                  [id] =&gt; 5363
                  [proname] =&gt; pro1
                  [company_id] =&gt; 101
              )
  
          [1] =&gt; Array
              (
                  [id] =&gt; 5367
                  [proname] =&gt; pro4
                  [company_id] =&gt; 101
              )
          [2] =&gt; Array
              (
                  [id] =&gt; 5371
                  [proname] =&gt; pro9
                  [company_id] =&gt; 101
              )
  
          )
      [1]=Array
          (
          [0] =&gt; Array
              (
                  [id] =&gt; 5364
                  [proname] =&gt; pro2
                  [company_id] =&gt; 105
              )
          [1] =&gt; Array
              (
                  [id] =&gt; 5368
                  [proname] =&gt; pro5
                  [company_id] =&gt; 105
              )
          [2] =&gt; Array
              (
                  [id] =&gt; 5369
                  [proname] =&gt; pro6
                  [company_id] =&gt; 105
              )
          [3] =&gt; Array
              (
                  [id] =&gt; 3849
                  [proname] =&gt; pro8
                  [company_id] =&gt; 105
              )
           [4] =&gt; Array
              (
                  [id] =&gt; 5385
                  [proname] =&gt; pro11
                  [company_id] =&gt; 105
              )
          )
  
      [2]=Array(
           [0] =&gt; Array
              (
                  [id] =&gt; 5366
                  [proname] =&gt; pro3
                  [company_id] =&gt; 102
              )
            [1] =&gt; Array
              (
                  [id] =&gt; 3847
                  [proname] =&gt; pro7
                  [company_id] =&gt; 102
              )
          [2] =&gt; Array
              (
                  [id] =&gt; 5383
                  [proname] =&gt; pro10
                  [company_id] =&gt; 102
              )
      )
  
  )
  </code></pre>
  
  <p>aim is to make group as for company.</p>