php Programming Exercies

PHP Exercises: Remove duplicates from a sorted list

PHP: Exercise-35 with Solution

Write a PHP program to remove duplicates from a sorted list.

Input: (1,1,2,2,3,4,5,5)
Output: (1,2,3,4,5)

Sample Solution: -

PHP Code:

function remove_duplicates_list($list1) {
  $nums_unique = array_values(array_unique($list1));
  return $nums_unique ;
$nums = array(1,1,2,2,3,4,5,5);

Sample Output:

    [0] => 1                                                
    [1] => 2                                                
    [2] => 3                                                
    [3] => 4                                                
    [4] => 5                                                

PHP Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a PHP program to check if the bits of the two given positions of a number are same or not.
Next: Write a PHP program to test if a given string occurs at the end of another given string.

What is the difficulty level of this exercise?

New Content: Composer: Dependency manager for PHP, R Programming