A usefull function in PHP

By Nisse Pettersson at August 27, 2009 06:54
Filed Under: Technical
Share on Facebook

I've came across a problem where I don't want any duplicates in an array. I'm not that familiar with the functions PHP have for arrays. So I Googled for some answers and found out that there is a neat function ready.
It's called array_unique.

$input = array("a" => "green", "red", "b" => "green", "blue", "red");
print_r($input);


Will produce the following result.

Array 
( 
    [a] => green 
    [0] => red 
    [1] => blue 
)

More on array_unique



Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading