Last active
May 17, 2020 05:29
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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