title: Creating an associative array from one-dimension array
body: <p><em>Was not really sure on what question's title should be here...</em> </p>
  
  <p><strong>Sample .csv</strong>:</p>
  
  <pre><code>tennis,soccer,sports
  car,plane,things
  jeans,shirt,things
  </code></pre>
  
  <p><strong>My final, <em>ideal</em>, outcome should be an array that looks like this:</strong></p>
  
  <pre><code>Array
  (
      [sports] =&gt; Array
          (
              [0] =&gt; tennis
              [1] =&gt; soccer
          )
  
      [things] =&gt; Array
          (
              [0] =&gt; car
              [1] =&gt; plane
              [2] =&gt; jeans
              [3] =&gt; shirt
          )
  
  )
  </code></pre>
  
  <p><strong>Here is my most recent attempt to achieve the outcome above (after many tries):</strong></p>
  
  <pre><code>&lt;?php
  $f_name = 'test.csv';
  // Stores all csv data
  $csv_data = array_map('str_getcsv', file($f_name));
  $c = count($csv_data);
  
  $tmp = array();
  $data_for_email = array();
  
  for ($i = 0; $i &lt; $c; $i++) {
      // Remove last element and make it a key
      $le = array_pop($csv_data[$i]);
      $tmp[$le] = $csv_data[$i];
      $data_for_email = array_merge_recursive($data_for_email, $tmp); // MEMORY ERROR
  }
  
  print_r($data_for_email);
  ?&gt;
  </code></pre>
  
  <p><strong>This is what I get as a result:</strong></p>
  
  <pre><code>Array
  (
      [sports] =&gt; Array
          (
              [0] =&gt; tennis
              [1] =&gt; soccer
              [2] =&gt; tennis
              [3] =&gt; soccer
              [4] =&gt; tennis
              [5] =&gt; soccer
          )
  
      [things] =&gt; Array
          (
              [0] =&gt; car
              [1] =&gt; plane
              [2] =&gt; jeans
              [3] =&gt; shirt
          )
  
  )
  </code></pre>
  
  <p>As you can see, I get duplicates of .csv's line 1 in <code>[sports]</code> array.</p>
  
  <p>More detailed description of my requirement:</p>
  
  <ol>
  <li>Each line has 3 fields.</li>
  <li>3rd field becomes a <code>key</code> in a new associative array.</li>
  <li>Two remaining fields (1st and 2nd) become <code>values</code> for that <code>key</code>.</li>
  <li>Because multiple lines may (and do) contain identical 3rd field (while combination of 1st and 2nd fields are always different), I need to then merge all these duplicate keys' values into 1.</li>
  </ol>
  
  <p>P.S. I could parse that array (to remove duplicate values) afterwards, but the real .csv file is large and it becomes too slow to process it, and I receive the following error at the line which I marked with <code>// MEMORY ERROR</code>:</p>
  
  <blockquote>
    <p>Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted</p>
  </blockquote>
  
  <p>I tried increasing the memory limit but I'd prefer to avoid this if possible.</p>