×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: userc865b
Added: Jun 9, 2017 10:26 AM
Views: 15
Tags: php
  1. $a = array(1, 1, 2, 3, 4, 5, 99, 2, 5, 2);
  2.  
  3. $unique     = array_unique($a); // preserves keys
  4. $diffkeys   = array_diff_key($a, $unique);
  5. $duplicates = array_unique($diffkeys);
  6.  
  7. echo 'Duplicates: ' . join(' ', $duplicates) . "\n"; // 1 2 5