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
Depending on the size of your array, I have found
can be faster than array_unique.
Here I've created a second empty array and used
for
loop with the first array which is having duplicates. It will run as many time as the count of the first array. Then compared with the position of the array with the first array and matched that it has this item already or not by usingin_array
. If not then it'll add that item to second array witharray_push
.I have done this without using any function.
first time check value in array and found same value ignore it
sometimes
array_unique()
is not the way, if you want get unique AND duplicated items...results on