...

View Full Version : Remove Member from Array



rynox
10-14-2003, 06:07 PM
Is there a built in function that will remove a member from an array or should I build my own?

Ryan

mordred
10-14-2003, 07:48 PM
There is. It's called unset().



$foo = array('apple', 'pear', 'mango');
unset($foo[1]);
var_dump($foo);


Watch out if you intend to iterate over the modified array, because unset() does not cause it to re-index itself. Use $foo = array_values($foo) or a foreach-loop instead. With associative arrays, you don't have this problem.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum