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 Quote Link to comment 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 Quote Link to comment 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() 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.