duplicate record in array

07-13-08, 12:38 PM
|
|
Wannabe Coder
|
|
Join Date: Mar 2007
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
duplicate record in array
i assign approximately 1000 record into an array called $x
how can i list duplicate record in array ?
|

07-14-08, 09:26 AM
|
 |
Community Liaison
|
|
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
|
|
You could also use array_count_values(), arsort(), and array_diff():
PHP Code:
// dummy values $vals = array( 'One', 'Two', 'Three', 'Four', 'Five', 'One', 'Two', 'Three', 'Two', 'Three', );
// get number of instances per value $vals = array_count_values( $vals );
// sort values by count from most frequent to least arsort( $vals );
// optional, removes all values that appear only once $vals = array_diff( $vals, array( '1' ) );
print_r( $vals );
...will output:
__________________
The toxic ZCE
|

07-14-08, 01:13 PM
|
|
Wannabe Coder
|
|
Join Date: Mar 2007
Posts: 191
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
İ can list users in db using following
i can list duplicate record in array using following
PHP Code:
$array = array('a', 'b', 'a', 'a', 'c', 'a', 'd', 'a', 'c', 'd','e','e','e','e','e','e','e','e','e','e','e','e');
$answer = array_count_values($array);
$i=0;
foreach($array as $value){
if($answer[$array[$i]] >2){
echo $value.$answer[$array[$i]]."<br/>";
}
$i++;
}
how can i merge both of them ? ( i tried but i can not)
|

07-14-08, 01:35 PM
|
 |
-
|
|
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|