title: How to populate missing array data by flipping 2nd and 3rd level keys?
body: <p>I have a multidimensional array and I need to ensure that paired/related subarrays are generated in the deepest level of my array.</p>
  <p>The idea is that subarrays [65][1] and [155][1] should exist. At the same time, subarrays [65][2] and [155][2] should exist.</p>
  <p>In other words, [nn][1] and [nn][2] must exist.</p>
  <p>I would like to be able to automatically add subarrays which do not exist. I do not know how to do it with PHP.</p>
  <p>So, I am looking for a code which goes through the array and creates subarrays which do not exist.</p>
  <p>Here is an example.</p>
  <pre><code>Array (
    [65] =&gt; Array (
      [1] =&gt; Array (
        [2] =&gt; Array (
          [points] =&gt; 0000000600
          [competition] =&gt; 0000000011
        )
      )
    )
  
    [155] =&gt; Array (
      [1] =&gt; Array (
        [2] =&gt; Array (
          [points] =&gt; 0000000900
          [competition] =&gt; 0000000011
        )
      )
  
      [2] =&gt; Array (
        [1] =&gt; Array (
          [points] =&gt; 0000000750
          [competition] =&gt; 0000000025
        )
      )
    )
  }
  </code></pre>
  <p>However, the subarray [65][2] does not exist.</p>
  <p>As said, I am looking for a code which goes through the array and creates subarrays which do not exist.</p>
  <p>The result should look like this:</p>
  <pre><code>Array (
    [65] =&gt; Array (
      [1] =&gt; Array (
        [2] =&gt; Array (
          [points] =&gt; 0000000600
          [competition] =&gt; 0000000011
        )
      )
  
  /* this should be added automatically */
  
      [2] =&gt; Array (
        [1] =&gt; Array (
          [points] =&gt; 0000000000
          [competition] =&gt; 0000000000
        )
      )
    )
  
  /* */
  
    [155] =&gt; Array (
      [1] =&gt; Array (
        [2] =&gt; Array (
          [points] =&gt; 0000000900
          [competition] =&gt; 0000000011
        )
      )
  
      [2] =&gt; Array (
        [1] =&gt; Array (
          [points] =&gt; 0000000750
          [competition] =&gt; 0000000025
        )
      )
    )
  }
  </code></pre>
  <p>Notice that the default data is assign to a new subarray which is assigned 2nd and 3rd level keys using the 3rd and 2nd level keys respectively.</p>