← Back to Gists

Remove duplicates array

📝 PHP
stephaniem
stephaniem · Level 5 ·

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

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?