How can I remove duplicate values from an array in PHP?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
If you concern in performance and have simple array, use:
It's many times faster than array_unique.
It can be done through function I made three function duplicate returns the values which are duplicate in array.
Second function single return only those values which are single mean not repeated in array and third and full function return all values but not duplicated if any value is duplicated it convert it to single;
explode(",", implode(",", array_unique(explode(",", $YOUR_ARRAY))));
This will take care of key associations and serialize the keys for the resulting new array :-)
Remove duplicate values from an associative array in PHP.
Array ( [0] => aaa-aaa [1] => 12/1/1 [2] => 1.15 )
try this short & sweet code -
Output -