You are here: Home / Topics / Remove The Duplicate Values From An Array in PHP

Remove The Duplicate Values From An Array in PHP

Filed under: PHP on 2022-11-16 13:51:50

The below program is to remove the duplicate values from an array using PHP array_unique() function. The PHP echo statement is used to output the result on the screen. An array is a single variable which can store multiple values at a time. The PHP array_unique() function is used to remove the duplicate elements from an array.
 

Example:

<!DOCTYPE html>
<html>
<body>

<?php
$arr = array("London","Paris","Switzerland","Switzerland","Scotland");
print_r(array_unique($arr));
?>

</body>
</html>
 

Output:

Array ( [0] => London [1] => Paris [2] => Switzerland [4] => Scotland )

About Author:
D
Deepak Sahoo     View Profile
I am preparing for UPSC. My dream is to be IAS.