[SOLVED] Drop empty keys (arrays)
Posted: Fri Jun 29, 2007 9:48 pm
I have an array of users. I have another array that contains users from the first array that I want deleted. This how I've attempted it:
I'm left with an array with holes in it. Is there a way to now collapse the array where there are null values? Should I be taking another approach all together?
Code: Select all
$masterlist = array(0 => "user0", 1 => "user1", 2 => "user2", 3 => "user3");
$dellist = array(0 => "user1", 1 => "user2");
foreach ($dellist as $needle) {
if (array_search($needle, $masterlist));
$masterlist[array_search($needle, $masterlist)] = null;
}
print_r($masterlist);