Duplicates in array elements and sorting
Since it's an interview, they're probably looking for one of two things:


You show that you understand logic
You know PHP


It's never advisable to "recreate the wheel", and PHP has built-in methods to do what you're looking for - for example:

// Count how many times each array value occurs in the array
$occurrences = array_count_values($numbers);
// Filter out any that aren't duplicates
$duplicates = array_filter($occurrences, function($count) { return $count &gt; 1; });
// Format the output as requested
$output = implode(',', array_keys($duplicates));


I note you don't say you have a requirement to sort anything, so don't bother.

If I were hiring you I'd obviously prefer you had both of the points above, but I'd rather that you used PHP to its ability as much as possible. Aside from that, this is a code review site, so the same answer would stand in that case. Example.