You can also create new uni dimensional array
with key like this '0-1' and run array_unique
and after come back to myarray

for example

foreach ($myarray as $key1 => $value)
    foreach($value as $key2 => $value2) $new_array["$key1-$key2"] = $value2
unset($myarray) ;

$new_array = array_unique($new_array) ;
foreach($new_array as $key => $value)
 if (ereg("([0-9])-([0-9])", $key, $reg) $myarray[$reg[1]][$reg[2]] = $value

----- Original Message -----
From: "René Fournier" <[EMAIL PROTECTED]>
Sent: Friday, November 15, 2002 7:31 AM
Subject: [PHP] Removing duplicates in multi-dimensional array

I'm finding this one hard to approach...

I have a two-dimensional array, containing customer contact
information. Looks like:

$myarray[0][0] = "Microsoft";
$myarray[0][1] = "Bill";
$myarray[0][2] = "123-1234";

$myarray[1][0] = "Apple";
$myarray[1][1] = "Steve";
$myarray[1][2] = "456-1234";     <<<<<

$myarray[2][0] = "Oracle";
$myarray[2][1] = "Larry";
$myarray[2][2] = "987-4321";

$myarray[3][0] = "Pixar";
$myarray[3][1] = "Steve";
$myarray[3][2] = "456-1234";     <<<<<

What I want to do is remove records that have the same fax number, so
that each fax number occurs only once. For example,  $myarray[1][2] and
$myarray[3][2] are the same--I would like to remove/unset one of them.

I know that array_unique() will do this for one-dimensional arrays, but
I'm kinda stuck here, since the repeating element is in the second
dimension. Any ideas how I might do this?



René Fournier,

Toll-free +1.888.886.2754
Tel +1.403.291.3601
Fax +1.403.250.5228

SmartSlitters International
#33, 1339 - 40th Ave NE
Calgary AB  T2E 8N6

PHP General Mailing List (
To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to