Home How To Return Duplicate Elements in Array PHP

How To Return Duplicate Elements in Array PHP

44 viewsPHP
0
<?php
$array = array(1,2,2,4,4,5);
$dublicate = array();
foreach ( array_count_values($array) as $key=>$value) {

          if($value > 1) {
            $dublicate = $key;
            print_r( $dublicate );
          }
}

?>

Output

2 4
Changed status to publish