Skip to content

Instantly share code, notes, and snippets.

@zakirsajib
Last active May 17, 2020 05:29
Show Gist options
  • Save zakirsajib/4a6c66db54ccb3a97050ed899fed22c2 to your computer and use it in GitHub Desktop.
Save zakirsajib/4a6c66db54ccb3a97050ed899fed22c2 to your computer and use it in GitHub Desktop.
Implement a function distinct(...), which expects an array of integers and sorts these ascendingly. The array shall not contain repetitions of any integer value but '1'. Repetitions of '1' should be the last values of the array.
<?php
function distinct($input){
$result = array_unique($input);
sort($result);
$key = array_search(1, $result);
if(false !== $key):
array_push($result, 1);
endif;
print_r($result);
}
$input = array(3,3,1,1,9);
distinct($input);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment