Assuming that parts of a string
that consists of numbers separated by commas, you should do the following:
1-Convert the string into an array with the function explode
which is responsible for converting a string
in array given a delimiter, in this case the comma:
$variable= "1,2,3,4,5,6,7,8,9,1,2,3,4,8,9,1,2,3";
$array = explode(",",$variable);
2- Eliminate the repeated values of the array with the function array_unique
:
$array=array_unique($array);
3-Re-convert the array in string
with the function implode
that converts an array in string
separated by the given delimiter:
$variable=implode($array,",");
result:
1,2,3,4,5,6,7,8,9