How to remove duplication in a multi-dimensional array like this(PHP)
<p>I try to combine result from several queries and put them into an array. I found there are some duplications exist. What I want to do is keep the first record and remove the following same records if duplication exist. I want to write a function to filter array and remove duplications. Can anyone help me with it? thanks</p>

<pre><code>array(4) {
  [0]=&gt;
  array(14) {
    ["user_id"]=&gt;
    string(7) "2620613"
    ["first_name"]=&gt;
    string(5) "Susan"
    ["last_name"]=&gt;
    string(9) "Alexander"
    ["client"]=&gt;
    string(7) "Pro"
    ["ssn"]=&gt;
    string(9) "4234324"
    ["hiredate"]=&gt;
    string(10) "2008-04-11"
    ["hra_id"]=&gt;
    string(6) "43244"
    ["hra_date"]=&gt;
    string(10) "2011-08-17"
    ["hra_maileddate"]=&gt;
    NULL
    ["screening_id"]=&gt;
    string(6) "3764551"
    ["screening_date"]=&gt;
    string(10) "2011-08-12"
    ["screening_maileddate"]=&gt;
    NULL
    ["ref"]=&gt;
    string(1) "D"
    ["mailable"]=&gt;
    string(3) "Yes"
  }
  [1]=&gt;
  array(14) {
    ["user_id"]=&gt;
    string(7) "263453"
    ["first_name"]=&gt;
    string(6) "Dharti"
    ["last_name"]=&gt;
    string(6) "Surani"
    ["client"]=&gt;
    string(7) "Pro"
    ["ssn"]=&gt;
    string(9) "345325"
    ["hiredate"]=&gt;
    string(10) "2002-04-29"
    ["hra_id"]=&gt;
    string(6) "3455345"
    ["hra_date"]=&gt;
    string(10) "2010-03-22"
    ["hra_maileddate"]=&gt;
    NULL
    ["screening_id"]=&gt;
    string(6) "234234"
    ["screening_date"]=&gt;
    string(10) "2011-07-11"
    ["screening_maileddate"]=&gt;
    NULL
    ["ref"]=&gt;
    string(1) "D"
    ["mailable"]=&gt;
    string(3) "Yes"
  }
  [2]=&gt;
  array(14) {
    ["user_id"]=&gt;
    string(7) "2685056"
    ["first_name"]=&gt;
    string(4) "Alex"
    ["last_name"]=&gt;
    string(2) "Hu"
    ["client"]=&gt;
    string(7) "Pro"
    ["ssn"]=&gt;
    string(9) "000005562"
    ["hiredate"]=&gt;
    string(10) "2011-09-15"
    ["hra_id"]=&gt;
    string(6) "528948"
    ["hra_date"]=&gt;
    string(10) "2011-07-06"
    ["hra_maileddate"]=&gt;
    NULL
    ["screening_id"]=&gt;
    string(6) "377382"
    ["screening_date"]=&gt;
    string(10) "2011-06-15"
    ["screening_maileddate"]=&gt;
    NULL
    ["ref"]=&gt;
    string(1) "D"
    ["mailable"]=&gt;
    string(3) "Yes"
  }
  [3]=&gt;
  array(14) {
    ["user_id"]=&gt;
    string(7) "2685056"
    ["first_name"]=&gt;
    string(4) "Alex"
    ["last_name"]=&gt;
    string(2) "Hu"
    ["client"]=&gt;
    string(7) "Pro"
    ["ssn"]=&gt;
    string(9) "000005562"
    ["hiredate"]=&gt;
    string(10) "2011-09-15"
    ["hra_id"]=&gt;
    string(6) "528948"
    ["hra_date"]=&gt;
    string(10) "2011-07-06"
    ["hra_maileddate"]=&gt;
    NULL
    ["screening_id"]=&gt;
    string(6) "377971"
    ["screening_date"]=&gt;
    string(10) "2011-09-13"
    ["screening_maileddate"]=&gt;
    NULL
    ["ref"]=&gt;
    string(1) "E"
    ["mailable"]=&gt;
    string(3) "Yes"
  }
}
</code></pre>

<p>I try to use the following function to remove duplications, but it doesn't work very well and may cause error on some cases.</p>

<pre><code> $resultDE = array_merge($resultD1, $resultE1, $resultE2);
  function specified_array_unique($array) 
  { 
      for($i=0; $i&lt;count($array); $i++){
        if(($array[$i]['user_id'] == $array[$i+1]['user_id']) &amp;&amp; isset($array[$i+1]))
         unset($array[$i+1]); 
      }

      return $array; 
  } 

 var_dump(super_unique($resultDE));
</code></pre>
