mmgareth Posted August 5, 2009 Share Posted August 5, 2009 If I have an array.... $test = array("apple","orange","apple","apple","cherry"); the indexes are 0 = apple 1 = orange 2 = apple 3 = apple 4 = cherry When I remove duplicated using array_unique, I am left with this... 0 = apple 1 = orange 4 = cherry But I really want to be left with this... 0 = apple 1 = orange 2 = cherry I have tried $test = array_merge(array_flip(array_flip($test))), which seems to work, but gives Warning errors. 'array_flip() [function.array-flip]: Can only flip STRING and INTEGER values!' Can anyone help? Thanks Gareth Link to comment https://forums.phpfreaks.com/topic/168902-re-index-an-array-after-removing-duplicates/ Share on other sites More sharing options...
mmgareth Posted August 5, 2009 Author Share Posted August 5, 2009 I think I've fixed my own problem... $test = array_values($test); ... seems to work :-) Link to comment https://forums.phpfreaks.com/topic/168902-re-index-an-array-after-removing-duplicates/#findComment-891122 Share on other sites More sharing options...
haku Posted August 5, 2009 Share Posted August 5, 2009 That's exactly how you do it! Link to comment https://forums.phpfreaks.com/topic/168902-re-index-an-array-after-removing-duplicates/#findComment-891127 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.