Extracting Unique Values from an Array in PHP


Retrieve a list of unique values from an array using array_unique().

Source Code

$input = ["apple", "banana", "apple", "pear", "banana"];
$result = array_unique($input);
print_r($result); // Outputs: Array ( [0] => apple [1] => banana [3] => pear )
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments