Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.Recently I needed to figure out duplicate values in arrays and I have found a solution and after a while I needed it again so I thought that maybe this could be a useful function to have in Drupal right away.
/**
* Returns duplicated entries from the provided array.
* http://magp.ie/2011/02/02/find-duplicates-in-an-array-with-php/
*
* @param $array
*
* @return array
*/
public function getDuplicates(array $array) {
return array_values(array_unique(array_diff_assoc($array, array_unique($array))));
}
Comments
Comment #14
smustgrave commentedThank you for sharing your idea for improving Drupal.
We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #15
smustgrave commentedSince there's been no follow up and this was a feature request going to close out. If still desired please re-open
Thanks all