BrettCarr Posted September 1, 2011 Share Posted September 1, 2011 Hi guys im trying to get rid of records with duplicate phone numbers here's my array Array ( [0] => Array ( [0] => 11-1-89677-362123164 [1] => 11 [2] => testadmin [3] => 61415676836 [4] => 2011-11-16 [5] => 1 [6] => 0 [7] => 0 [8] => [9] => 0 [10] => 0 [11] => 0 ) [1] => Array ( [0] => 11-1-89688-362186603 [1] => 11 [2] => testadmin [3] => 61415556677 [4] => 2011-08-12 [5] => 0 [6] => 0 [7] => 0 [8] => [9] => 0 [10] => 0 [11] => 0 ) [2] => Array ( [0] => 11-1-89689-362186773 [1] => 11 [2] => testadmin [3] => 61415676836 [4] => 2011-08-12 [5] => 0 [6] => 0 [7] => 0 [8] => [9] => 0 [10] => 0 [11] => 0 ) [3] => Array ( [0] => 11-1-89690-362186926 [1] => 11 [2] => testadmin [3] => 61415223344 [4] => 2011-08-12 [5] => 0 [6] => 0 [7] => 0 [8] => [9] => 0 [10] => 0 [11] => 0 ) ) I can't quit figure this out any sujestions would be gold,,, this is my attempt but its not working $final = array(); foreach ($phoneNumberArray as $array[3]) { if(!in_array($array, $final)){ $final[] = $array; } } print_r($final); Quote Link to comment Share on other sites More sharing options...
joel24 Posted September 1, 2011 Share Posted September 1, 2011 use the array_unique() function Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 1, 2011 Share Posted September 1, 2011 use the array_unique() function That won't work on values in a sub-array of a mufti-dimensional array. $phones = array(); foreach ($phoneNumberArray as $index => $record) { if(!in_array($record[3], $phones)) { //First record with this phone number. add phone to the list and leave the record $phones[] = $record[3]; } else { //This phone was in a previous record, remove the record unset($phoneNumberArray[$index]); } } print_r($phoneNumberArray); Quote Link to comment Share on other sites More sharing options...
joel24 Posted September 1, 2011 Share Posted September 1, 2011 foreach ($array AS &$a) { $a=array_unique($a); } you can write that as a function and use an if (is_array($a)) to use it for arrays with more than 2 dimensions Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 1, 2011 Share Posted September 1, 2011 foreach ($array AS &$a) { $a=array_unique($a); } you can write that as a function and use an if (is_array($a)) to use it for arrays with more than 2 dimensions What? That won't work either. That would ensure that there are no duplicates values within any sub-array. The problem as displayed by the OP is that he wants to ensure there are no duplicates (of a particular value) between sub-arrays. array_unique() only works on values within a single dimension. It would work if those sub-arrays are exactly the same, but the OP only wants to exclude those where one value in the sub-array is a duplicate. Quote Link to comment Share on other sites More sharing options...
joel24 Posted September 2, 2011 Share Posted September 2, 2011 duplicates (of a particular value) between sub-arrays. took a quick glance and misread the question, apologies. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.