WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to remove duplicate values from an array in PHP

Topic: PHP / MySQLPrev|Next

Answer: Use the PHP array_unique() function

You can use the PHP array_unique() function to remove the duplicate elements or values form an array. If the array contains the string keys, then this function will keep the first key encountered for every value, and ignore all the subsequent keys. Here's an example:

<?php
$array = array("a" => "moon", "star", "b" => "moon", "star", "sky");
 
// Deleting the duplicate items
$result = array_unique($array);
print_r($result);
?>

Related FAQ

Here are some more FAQ related to this topic:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties