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