Image

Imagecyclotron wrote in Imagephp

Arrays - removing duplicating entries

Whats the best the way to elliminate the duplicate array entries?

Here's some sample data


I am comparing positions [1] [2] [3] [4]

Array
(
    [0] => Array
        (
            [0] => effe7ec6a86cebbf6873de64ff54df36
            [ID] => effe7ec6a86cebbf6873de64ff54df36
            [1] => 15553075555
            [TagPhone] => 1555305555
            [2] => Bill
            [TagSpokenName] => Bill
            [3] => 29
            [TimeZone_ID] => 29
            [4] => bill@email.com
            [TagEmail] => bill@email.com
            [5] => 32
            [ACCOUNT_ID] => 32
        )

    [1] => Array
        (
            [0] => 0d604cf13300a5253b7a317420f63f99
            [ID] => 0d604cf13300a5253b7a317420f63f99
            [1] => 15553075555
            [TagPhone] => 155553075555
            [2] => Bill
            [TagSpokenName] => Bill
            [3] => 0
            [TimeZone_ID] => 0
            [4] => bill@email.com
            [TagEmail] => bill@email.com
            [5] => 32
            [ACCOUNT_ID] => 32
        )

}




Here is a solution I came up with:



//Beginning array
$calllist

//Convert fields I want to compare to a string
$r=0;
while($r < count($calllist)-2 ){
$cltemp[$r] = $calllist[$r][1].$calllist[$r][2].$calllist[$r][3].$calllist[$r][4];
$r++;
}


//Get the unique rows
$clunique = array_unique($cltemp);

//Get the keys of the unique rows
$uniquekeys = array_keys($clunique);

//Use the keys to create areduced array
//Reset the first level arrays (seems to matter later)
$r=0;
foreach($uniquekeys as $key){
$cltemp2[$r] = $calllist[$key];
$r++;
}

//save the result array back toi the original array so that the code
//that follows continues to work
$calllist = $cltemp2;