Hey I'm trying to remove array results with dupes in one of the fields but I can't get it to work unless the entire array field is a dupe ie:

<?php
$items = array
      (
          'x' => array
              (
                  'y' => array
                      (
                          0 => array
                              (
                                  'ID' => 390517,
                                  'Name' => 'Bill'
                                  ),
                          1 => array
                              (
                                  'ID' => 390519,
                                  'Name' => 'Mike'
                                  ),
                          2 => array
                              (
                                  'ID' => 390533,
                                  'Name' => 'Sam'
                                  ),
                          3 => array
                              (
                                  'ID' => 390519,
                                  'Name' => 'Mike'
                                  )
                     )
              )
      );

/**
* remove dupes
*/
$a = $items['x']['y'];
$k = count($a);
for($i=0; $i < $k-1; $i++)
{
    for($j=$i+1; $j < $k; $j++)
    {
        if ($a[$i] == $a[$j]) unset($a[$j]);
    }
}
$items['x']['y'] = $a;
echo '<pre>', print_r($items, true), '</pre>';
?>

This works and removes the dupe of [1] & [3] but sometimes the ID field is diff. but since the name is the same I still want that array field removed.. IE:

$items = array
      (
          'x' => array
              (
                  'y' => array
                      (
                          0 => array
                              (
                                  'ID' => 390519,
                                  'Name' => 'Mike'
                         1 => array
                              (
                                  'ID' => 392434,
                                  'Name' => 'Mike'
                                  )
                     )
              )
      );

Should trigger a dupe and only print 1 array field. Any thoughts?

    Write a Reply...