title: how to add elements to an array in a loop using php
body: <p>I am dynamically trying to populate a multidimensional array and having some trouble.</p>
  
  <p>I have a list of US states. Associative array like this $states[nc], $states[sc], etc. in my loop I want to append cities onto each state so $states[nc][cities] contains an array of cities. Im stuck with the logic.</p>
  
  <pre><code>foreach($states as $state) {
      $data[$state] = $state;
  
      foreach($cities as $city) {
        $data[$state]['cities'] .= $city;
       }
  }
  </code></pre>
  
  <p>I know that concatenation is not correct, but I am not sure how to add elements to this array. I keep getting errors with array_push.</p>
  
  <p>What's the correct way to add these elements?</p>