title: How to convert 3 dimensional array into 2 dimensional array in PHP?
body: <p>I have below 3D array:</p>
  <pre><code>$data = [
  
      '1'=&gt;[
          '1' =&gt; [
              '1' =&gt; 1,
              '2' =&gt; 2        
          ],
          '2' =&gt; [
              '3' =&gt; 3,
              '4' =&gt; 4        
          ]
      ],
      '2'=&gt;[
          '3' =&gt; [
              '5' =&gt; 5,
              '6' =&gt; 6        
          ],
          '4' =&gt; [
              '7' =&gt; 7,
              '8' =&gt; 8        
          ]
      ],
  ];
  </code></pre>
  <p>In this array first iterator is for 'category' which should iterate only two times. Second iterator is for 'attribute' which should iterate four times and third iterator have 8 values, which are for 'option'.</p>
  <p>The output should look like below two dimensional array.</p>
  <pre><code>$data = [
  
      ['category'=&gt;1,'attribute'=&gt;1,'option'=&gt;1],
      ['category'=&gt;1,'attribute'=&gt;1,'option'=&gt;2],
      ['category'=&gt;1,'attribute'=&gt;2,'option'=&gt;3],
      ['category'=&gt;1,'attribute'=&gt;2,'option'=&gt;4],
      ['category'=&gt;2,'attribute'=&gt;3,'option'=&gt;5],
      ['category'=&gt;2,'attribute'=&gt;3,'option'=&gt;6],
      ['category'=&gt;2,'attribute'=&gt;4,'option'=&gt;7],
      ['category'=&gt;2,'attribute'=&gt;4,'option'=&gt;8]
  ];
  </code></pre>
  <p>I have done like this:</p>
  <pre><code>$newarr = array();
  
  foreach ($data as $subarray){
  
      foreach ($subarray as $key =&gt; $value) {
  
          foreach ($value as $k =&gt; $v) {
  
          $newarr[$v] = array('category' =&gt; $subarray,'attribute'=&gt;$value,'option'=&gt;$v);
          }
      }
  }
  
  
  print_r($newarr);
  </code></pre>
  <p>But I am able to fetch only option's value, not category and attribute values.</p>
  <p>Thanks.</p>