fork download
  1. <?php
  2.  
  3. function array_remove_unique(array $array) {
  4. $tmp = [];
  5. foreach($array as $item) {
  6. if(isset($tmp[$item])) {
  7. $tmp[$item] += 1;
  8. }
  9. else {
  10. $tmp[$item] = 1;
  11. }
  12. }
  13.  
  14. $array = [];
  15. foreach($tmp as $key => $value) {
  16. if($value > 1) {
  17. $array[] = $key;
  18. }
  19. }
  20. return $array;
  21. }
  22.  
  23. $array = [1,1,2,3,4,2,5];
  24. print_r($array);
  25. print_r(array_remove_unique($array));
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 1
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 4
    [5] => 2
    [6] => 5
)
Array
(
    [0] => 1
    [1] => 2
)