I think this might be easier...it should keep your associative array keys intact....This will sort an array of 1-dimensional arrays as such:
$input_array=array(0 =>
array('name' => 'Zeus',
'email' => 'zeus@domain.com'),
1=>
array('name' => 'Mary',
'email' => 'mary@domain.com'),
2=>
array('name' => 'Peter',
'email' => 'pete@domain.com')
);
//now to sort on the key 'name' in the input arrays, we would do this:
foreach ($input_array as $val) {
$sortarray[] = $val[name];
}
array_multisort($sortarray,SORT_ASC,SORT_REGULAR,$input_array);
unset($sortarray);
//now $input_array will look like this...
array(0 =>
array('name' => 'Mary',
'email' => 'mary@domain.com'),
1=>
array('name' => 'Peter',
'email' => 'pete@domain.com')
2=>
array('name' => 'Zeus',
'email' => 'zeus@domain.com'),
);
//if you wanted to do a numeric sort you would change SORT_REGULAR to SORT_NUMERIC.
That's it. Hope that helps.
Incedentally, to remove your duplicates, just loop through the array and find the $key of the first duplicate, then use array_splice($key) to remove the array element. If the array is sorted, you should only need to check if the current element is the same as the last one and if so remove it. You'd only need to traverse the array once this way.