View Single Post
Old 06-25-2009, 09:48 PM   #10 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I prefer that way using array_diff. It is a handy function. Otherwise either array_keys or array_search works just as well as one another.

Was it coincidence that your array outputs as ABBA?

One thing somebody might want though is to rebuild the indexes once some items have been removed. Therefore all the indexes now increment nicely again.

php Code:
$array  = array('a', 'b', 'c', 'd', 'c', 'b', 'a');
$remove = array('c', 'd', 'f', 'Bleh'); // or just, 'c'
$array  = array_diff($array, (array) $remove);
$array = array_values($array); // restores the indexes
print_r($array);
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote