title: PHP: Initializing associative Array Fields and appending text to them - without knowing the key values beforehand
body: <p>I would like to improve resp. shorten my programming style for initializing fields of associative arrays and appending text to them. </p>
  
  <p>The way I do it for years, example: </p>
  
  <pre><code>foreach($tagsArray as $tag) {
      if(!isset($mainArray[$tag])) {
          $mainArray[$tag] = '&lt;li&gt;'.$tag.'&lt;/li&gt;';
      }
      else {
          $mainArray[$tag] .= '&lt;li&gt;'.$tag.'&lt;/li&gt;';
      }
  }
  </code></pre>
  
  <p>It just feels too long.</p>
  
  <p>Can anyone provide me a shortcut for this? Can we directly init without checking with <code>isset</code>? </p>
  
  <p>Thanks. </p>