To remove duplicates from an array in PHP, you can use the `array_unique()` function.
In this example,
<?php
$numbers = [1, 2, 2, 3, 4, 4, 5];
$uniqueNumbers = array_unique($numbers);
print_r('Array without duplicates: ' . json_encode($uniqueNumbers));
?>
Array without duplicates: [1, 2, 3, 4, 5]
In this example,
<?php
$colors = ['red', 'green', 'blue', 'green', 'yellow', 'blue'];
$uniqueColors = array_unique($colors);
print_r('Array without duplicates: ' . json_encode($uniqueColors));
?>
Array without duplicates: ['red', 'green', 'blue', 'yellow']
In this tutorial, we learned How to Remove Duplicates in an Array in PHP language with well detailed examples.