php array unique

Associate
Joined
19 Jul 2006
Posts
1,847
Looking for a bit of help,
I have created a function that will return an associative array though I could change this if it would be better.
output is something like
PHP:
Array ( [0] => 123ABCStreet [1] => 123ABCStreet [2] => 321CBAStreet )

I then need to do something like this

for values that are unique {
return $unique key
}
for duplicates {
return $duplicates key
}

any pointers in the right direction.
 
Associate
Joined
19 Aug 2011
Posts
107
I suggest that maybe you can have a look at:

foreach( $yourAssocArray as $key => $value) {}

&

array_push(), in_array()

which could help you to create a few arrays which contain unique and duplicate keys/values.
 
Associate
Joined
22 Jun 2012
Posts
1,070
foreach($array as $key => $value):
if(isset($unique[$key])):
$unique[$key] = $value;
else:
$duplicate[$key] = $value;
endif;
endforeach;

Fairly similar to suggested above.
 
Back
Top Bottom