← Back to Gists

Remove duplicates array

📝 PHP
stephaniem
stephaniem · 5d ago
This PHP code snippet removes duplicate values from an array using the built-in `arrayunique` function.
PHP
<?php
$array = [1, 2, 2, 3, 4, 4, 5];
$uniqueArray = arrayunique($array);
printr($uniqueArray);
?>

Comments

0
leeb leeb 1d ago
the arrayunique preserves keys by default, which can trip you up if you're expecting a zero-indexed result. did you test it with associative arrays?