title: Convert PHP multidimensional array so that the values become keys, and and other values become arrays for each key
body: <p>I have:</p>
  
  <pre><code>    ['countryCode' =&gt; 11, 'postalCode' =&gt; 12345],
      ['countryCode' =&gt; 11, 'postalCode' =&gt; 12346],
      ['countryCode' =&gt; 11, 'postalCode' =&gt; 12347],
      ['countryCode' =&gt; 11, 'postalCode' =&gt; 12348],
      ['countryCode' =&gt; 11, 'postalCode' =&gt; 12349],
      ['countryCode' =&gt; 12, 'postalCode' =&gt; 12345],
      ['countryCode' =&gt; 12, 'postalCode' =&gt; 12346],
      ['countryCode' =&gt; 12, 'postalCode' =&gt; 12347],
      ['countryCode' =&gt; 12, 'postalCode' =&gt; 12348],
      ['countryCode' =&gt; 12, 'postalCode' =&gt; 12349],
  ];
  </code></pre>
  
  <p>But I want:</p>
  
  <pre><code>    '11' =&gt; ['12345, 12346, 12347, 12348, 12349'], '12' =&gt; ['12345, 12346, 12347, 12348, 12349']
  ];
  </code></pre>
  
  <p>I've tried:</p>
  
  <pre><code>$countries = array_column($data, 'countryCode');
  $countries = array_unique($countries);
  $countries = array_fill_keys($countries, []);
  
  function makeArrays(&amp;$countries, $data){
      foreach ($countries as $countryId =&gt; $postalCodes){
          foreach ($data as $item) {
              if ($item['countryCode'] == $countryId) {
                  array_push($postalCodes, $item['postalCode']);
              }
          }
      }
      return $countries;
  }
  
  makeArrays($countries, $data);
  </code></pre>
  
  <p>When I var_dump the makeArrays function though, the country ID keys are not populated with an array of postal codes like I would expect:</p>
  
  <pre><code>array(2) {
    [11]=&gt;
    array(0) {
    }
    [12]=&gt;
    array(0) {
    }
  }
  </code></pre>
  
  <p>How do I get each key's array to populate with the expected values?</p>