JKG Posted August 25, 2011 Share Posted August 25, 2011 hello, is there any way that i can take a string like this: 99,99,28,99,28,112,78,99,28,112,78,28,112,78,112,78,112, and find and remove the recurring numbers so i am left with this:? 99,28,112,78 thanks for your time Joe Link to comment https://forums.phpfreaks.com/topic/245696-find-and-delete-recurring-numbers/ Share on other sites More sharing options...
Psycho Posted August 25, 2011 Share Posted August 25, 2011 $string = '99,99,28,99,28,112,78,99,28,112,78,28,112,78,112,78,112,'; $string = trim(implode(',', array_unique(explode(',', $string))), ','); Explanation: explode() creates an array with each part separated by a comma as a value (note; there will be an empty value at the end due to the trailing space) array_unique() removes duplicate values from the array implode() Converts the array (of only unique values) back into a string separated by commas trim() removes the trailing comma due to the empty values in the original array Link to comment https://forums.phpfreaks.com/topic/245696-find-and-delete-recurring-numbers/#findComment-1261928 Share on other sites More sharing options...
JKG Posted August 25, 2011 Author Share Posted August 25, 2011 thank you so much, worked perfectly! wasnt aware of array_unique() Link to comment https://forums.phpfreaks.com/topic/245696-find-and-delete-recurring-numbers/#findComment-1261938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.