in_array(); | remove duplicate item from array?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

in_array(); | remove duplicate item from array?

Post 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
Reviresco
Forum Contributor
Posts: 172
Joined: Tue Feb 19, 2008 4:18 pm
Location: Milwaukee

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

Post by Reviresco »

Code: Select all

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