Created
June 30, 2016 09:30
-
-
Save azlan/3ded55c980e63b123fac8e57330f4155 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
$array = array(1,2,3,2,4,5,4); | |
sort($array); | |
$new_array = array(); | |
$duplicate = -1; | |
$x = 0; | |
for ($x = 0; $x < count($array)-1; $x++) { | |
if ($array[$x] != $array[$x+1] && $array[$x] != $duplicate) { | |
array_push($new_array,$array[$x]); | |
} else { | |
$duplicate = $array[$x]; | |
} | |
} | |
if($array[$x] != $array[$x-1]) | |
array_push($new_array,$array[$x]); | |
print_r($new_array); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment