Add getDuplicates() method into DiffArray utility class

Created on 27 April 2015, about 10 years ago
Updated 11 May 2025, 1 day ago

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))));
  }
✨ Feature request
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

other

Created by

Live updates comments and jobs are added and updated live.
  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank 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!

Production build 0.71.5 2024