Re: [PHP] Removing duplicates in multi-dimensional array

2002-11-14 Thread rija
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
[UNTESTED]

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]>
To: "php" <[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?

Thanks.

...Rene

---
René Fournier,
[EMAIL PROTECTED]

Toll-free +1.888.886.2754
Tel +1.403.291.3601
Fax +1.403.250.5228
www.smartslitters.com

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


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Removing duplicates in multi-dimensional array

2002-11-14 Thread Jonathan Sharp
When you build your 2d array you could make a seperate 1d array that's
indexed by the fax number and if it's set, not set it in your array...

-js


René Fournier wrote:
> 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?
> 
> Thanks.
> 
> Rene
> 
> ---
> René Fournier,
> [EMAIL PROTECTED]
> 
> Toll-free +1.888.886.2754
> Tel +1.403.291.3601
> Fax +1.403.250.5228
> www.smartslitters.com
> 
> SmartSlitters International
> #33, 1339 - 40th Ave NE
> Calgary AB  T2E 8N6
> Canada
> 
> 




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php