PHP: Removing Duplicates in an Array

April 8th, 2010

One thing I keep forgetting is that PHP has a built-in function for removing duplicate items from an array; I usually find myself about halfway through writing such a function when the lightbulb goes off.

$original = array ('pie', 'cake', 'cookies', 'cake');
$clean = array_unique($original);

The $clean array above would contain one less reference to cake than the $original array.

 

Musings on Coding, Gaming, and Life in General
Loading...