HTML
<form method="post">
<input type="text" name="values" value="1,2,1,3,4,2,2,5" />
<button type="submit">Submit</button>
</form>
PHP
if(isset($_POST['values']))
{
$values = $_POST['values']); //remove duplicate numbers
echo $values;
}
Output
1,2,3,4,5
How would that work? First sort the numbers? And then run them through a loop?
Your intution is correct: You’d sort and then loop.
But PHP already has built-ins that do all the work for you. Like this:
and if you need a string again, use implode: