[PHP] opposite of array_unique()?

2004-08-04 Thread Adam Williams
array_unique() removes duplicate values from an array.

Is there an opposite function or way of keeping all values in a single 
dimentional array that are duplicates and removing all that are 
duplicates?

for example if I have an array:

array( [0] = 'dog', [1] = 'cat', [2] = 'rabbit', [3] = 'cat')

how do I make it just have array ( [0] = 'cat' )?  i want to drop the 
non-duplicates and trim the array to only have one of the duplicates?



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



Re: [PHP] opposite of array_unique()?

2004-08-04 Thread Afan Pasalic
$animals = array('dog', 'cat', 'rabbit', 'cat');
$duplicates = array_count_values($animals);
foreach($duplicates as $key = $value)
if($value  1)
$new_array[] = $key;
print_r($new_array);

afan
At 02:20 PM 8/4/2004, Adam Williams wrote:
array_unique() removes duplicate values from an array.
Is there an opposite function or way of keeping all values in a single
dimentional array that are duplicates and removing all that are
duplicates?
for example if I have an array:
array( [0] = 'dog', [1] = 'cat', [2] = 'rabbit', [3] = 'cat')
how do I make it just have array ( [0] = 'cat' )?  i want to drop the
non-duplicates and trim the array to only have one of the duplicates?

--
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] opposite of array_unique()?

2004-08-04 Thread Curt Zirzow
* Thus wrote Adam Williams:
 for example if I have an array:
 
 array( [0] = 'dog', [1] = 'cat', [2] = 'rabbit', [3] = 'cat')
 
 how do I make it just have array ( [0] = 'cat' )?  i want to drop the 
 non-duplicates and trim the array to only have one of the duplicates?

If you're pulling this data from a sql table, then you're better
off having the database server do this work for you.


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

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



Re: [PHP] opposite of array_unique()?

2004-08-04 Thread Jason Davidson
you could loop thru the array, and using a nested loop, test each value
against all other values.. and keep ones that match in a new array.

But as mentioned, SQL would be easier.


Jason

Curt Zirzow [EMAIL PROTECTED] wrote: 
 
 * Thus wrote Adam Williams:
  for example if I have an array:
  
  array( [0] = 'dog', [1] = 'cat', [2] = 'rabbit', [3] = 'cat')
  
  how do I make it just have array ( [0] = 'cat' )?  i want to drop the 
  non-duplicates and trim the array to only have one of the duplicates?
 
 If you're pulling this data from a sql table, then you're better
 off having the database server do this work for you.
 
 
 Curt
 -- 
 First, let me assure you that this is not one of those shady pyramid schemes
 you've been hearing about.  No, sir.  Our model is the trapezoid!
 
 -- 
 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