unkwntech Posted August 6, 2008 Share Posted August 6, 2008 I should know this. What is the easyest way to remove an item from an array and reset the indexes I have $array = array('1','2','3','4','5'); unset($array['3']); Now i need the array to look like this after I do that: Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 5 ) Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 You could do: $array = array_values($array); >_> Quote Link to comment Share on other sites More sharing options...
unkwntech Posted August 6, 2008 Author Share Posted August 6, 2008 This could work, basically I'm looking for something to reset the array indexes. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 That's how you do it. I just found the line on the manual: Note: The unset() function allows removing keys from an array. Be aware that the array will not be reindexed. If a true "remove and shift" behavior is desired, the array can be reindexed using the array_values() function. Under the Useful Functions section Quote Link to comment Share on other sites More sharing options...
unkwntech Posted August 6, 2008 Author Share Posted August 6, 2008 ahh. ok.... I just figured out how to do it, with the function you suggest. $array = array('1','2','3','4','5'); unset($array['3']); $array = array_values($array); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.