Page 1 of 1

in_array(); | remove duplicate item from array?

Posted: Wed Nov 11, 2009 9:38 am
by $var
hi!
i am working on a photo gallery thumbnail index that has a featured gallery position.
in my thumbnail index, I need to omit the featured gallery 'id' if it exists, so that i don't have the featured gallery duplicated in the thumbnail index.

i understand that using in_array($id, $array); will help me discern if an '$id' appears in an '$array'.
what i don't understand is how to write:

if the $id is in the $array, remove $id and build new $array without it.

could someone help explain that with functions?

thank you so much DevNet

Re: in_array(); | remove duplicate item from array?

Posted: Wed Nov 11, 2009 10:39 am
by Reviresco

Code: Select all

$new_array = array_unique($array);
http://php.net/manual/en/function.array-unique.php