Giddy Rob Posted May 27, 2008 Share Posted May 27, 2008 Hi, I have an array of items and I need to reset the index values when one has been deleted. For example - if I have a sequence of 0 => a 1 => b 2 => c 3 => d 4 => e and 2 is deleted from the array it shifts all the records up so that I am left with: 0 => a 1 => b 2 => d 3 => e I need this as I am outputting using a for loop which counts the items from 0 up to how many are in the array. Anyone got a clue? Cheers in advance guys. Rob Link to comment https://forums.phpfreaks.com/topic/107488-reorder-the-index-values-of-an-array/ Share on other sites More sharing options...
rhodesa Posted May 27, 2008 Share Posted May 27, 2008 You can use $array = array_values($array); or, use a foreach loop instead of a for loop, then you wouldn't care about the keys: foreach($array as $item){ Link to comment https://forums.phpfreaks.com/topic/107488-reorder-the-index-values-of-an-array/#findComment-550951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.