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 ) Link to comment https://forums.phpfreaks.com/topic/118468-solved-array-indexes/ Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 You could do: $array = array_values($array); >_> Link to comment https://forums.phpfreaks.com/topic/118468-solved-array-indexes/#findComment-609848 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. Link to comment https://forums.phpfreaks.com/topic/118468-solved-array-indexes/#findComment-609857 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 Link to comment https://forums.phpfreaks.com/topic/118468-solved-array-indexes/#findComment-609860 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); Link to comment https://forums.phpfreaks.com/topic/118468-solved-array-indexes/#findComment-609863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.