Jump to content

find and delete recurring numbers


JKG

Recommended Posts

$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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.