How to remove duplicate values from an array in PHP - Stack Overflow

PHOTO EMBED

Wed Nov 23 2022 21:55:46 GMT+0000 (Coordinated Universal Time)

Saved by @hassan_aheer #php

//Find duplicates 

$arr = array( 
    'unique', 
    'duplicate', 
    'distinct', 
    'justone', 
    'three3', 
    'duplicate', 
    'three3', 
    'three3', 
    'onlyone' 
);

$unique = array_unique($arr); 
$dupes = array_diff_key( $arr, $unique ); 
    // array( 5=>'duplicate', 6=>'three3' 7=>'three3' )

// count duplicates

array_count_values($dupes); // array( 'duplicate'=>1, 'three3'=>2 )
content_copyCOPY

$unique = array_unique($arr);

https://stackoverflow.com/questions/307650/how-to-remove-duplicate-values-from-an-array-in-php