How to delete duplicate elements in an array in php: You can use the php built-in function array_unique() function to delete. The array_unique() function is used to remove duplicate elements from the array and return the filtered array.
array_unique() function is used to remove duplicate values from an array. If two or more array values are the same, only the first value is retained and the other values are removed. This function returns the filtered array.
(Recommended tutorial: php graphic tutorial)
Grammar:
array_unique(array)
(Recommended learning video: php video tutorial )
Code implementation:
<?php $a=array("a"=>"red","b"=>"green","c"=>"red"); print_r(array_unique($a)); ?>
Output result:
Array ( [a] => red [b] => green )
The above is the detailed content of How to remove duplicate elements from an array in php. For more information, please follow other related articles on the PHP Chinese website!