title: Group array row data by two columns creating a new 3-level structure
body: <p>I have 1 arrays:</p>
  
  <pre><code>array(5) { // This is the keys on the CSV.
    [0]=&gt;
    array(4) {
      [0]=&gt;
      string(4) "user"
      [1]=&gt;
      string(4) "date"
      [2]=&gt;
      string(3) "md5"
      [3]=&gt;
      string(4) "sha1"
    }
    [1]=&gt;
    array(4) {
      [0]=&gt;
      string(4) "user1"
      [1]=&gt;
      string(8) "02/02/15"
      [2]=&gt;
      string(6) "123456"
      [3]=&gt;
      string(5) "54321"
    }
    [2]=&gt;
    array(4) {
      [0]=&gt;
      string(4) "user1"
      [1]=&gt;
      string(8) "02/03/15"
      [2]=&gt;
      string(6) "123456"
      [3]=&gt;
      string(5) "54321"
    }
    [3]=&gt;
    array(4) {
      [0]=&gt;
      string(5) "user2"
      [1]=&gt;
      string(8) "02/02/15"
      [2]=&gt;
      string(6) "112233"
      [3]=&gt;
      string(6) "332211"
    }
    [4]=&gt;
    array(4) {
      [0]=&gt;
      string(5) "user2"
      [1]=&gt;
      string(8) "02/03/15"
      [2]=&gt;
      string(6) "112244"
      [3]=&gt;
      string(6) "332244"
    }
  }
  </code></pre>
  
  <p>So User 1 and User 2 each have a file that is MD5/SHA1 sum'd and checked.</p>
  
  <p>I would like the data to turn from the above, to this:</p>
  
  <pre><code>array(3) {
    ["user"]=&gt;
    array(1) {
      ["date"]=&gt;
      array(2) {
        [0]=&gt;
        string(3) "md5"
        [1]=&gt;
        string(4) "sha1"
      }
    }
    ["user1"]=&gt;
    array(1) {
      ["02/02/15"]=&gt;
      array(2) {
        [0]=&gt;
        string(6) "123456"
        [1]=&gt;
        string(5) "54321"
      }
      ["02/03/15"]=&gt;
      array(2) {
        [0]=&gt;
        string(6) "123456"
        [1]=&gt;
        string(5) "54321"
      }
    }
    ["user2"]=&gt;
    array(1) {
      ["02/02/15"]=&gt;
      array(2) {
        [0]=&gt;
        string(6) "112233"
        [1]=&gt;
        string(6) "332211"
      }
      ["02/03/15"]=&gt;
      array(2) {
        [0]=&gt;
        string(6) "112244"
        [1]=&gt;
        string(6) "332244"
      }
    }
  }
  </code></pre>
  
  <p>So far, I'm close. Here is my code:</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL &amp; ~E_NOTICE);
  
  //Reading csv
  
  $csv = array_map('str_getcsv',file('/var/www/sums.csv'));
  
  debug($csv);
  //User list
  $userData = array();
  
  foreach ($csv as $user) {
          $ts = $user[1];
          $un = $user[0];
          $sums = array($user[2],$user[3]);
          $userPreProc[$un] = array($ts =&gt; $sums);
          $userData = array_merge($userPreProc, $userData);
  }
  
  debug($userData);
  
  function debug($db) {
          echo "&lt;pre&gt;";
          var_dump($db);
          echo "&lt;/pre&gt;";
  }
  ?&gt;
  </code></pre>
  
  <p>The issue here is that only the first 'user1' and 'user2' entries are merged to the new array, so it looks like this:</p>
  
  <pre><code>array(3) {
    ["user"]=&gt;
    array(1) {
      ["date"]=&gt;
      array(2) {
        [0]=&gt;
        string(3) "md5"
        [1]=&gt;
        string(4) "sha1"
      }
    }
    ["user1"]=&gt;
    array(1) {
      ["02/02/15"]=&gt;
      array(2) {
        [0]=&gt;
        string(6) "123456"
        [1]=&gt;
        string(5) "54321"
      }
    }
    ["user2"]=&gt;
    array(1) {
      ["02/02/15"]=&gt;
      array(2) {
        [0]=&gt;
        string(6) "112233"
        [1]=&gt;
        string(6) "332211"
      }
    }
  }
  </code></pre>
  
  <p>Any suggestions how I can ensure that all the keys are merged as expected?</p>