Skip to content

Instantly share code, notes, and snippets.

@azlan
Created June 30, 2016 09:30
Show Gist options
  • Save azlan/3ded55c980e63b123fac8e57330f4155 to your computer and use it in GitHub Desktop.
Save azlan/3ded55c980e63b123fac8e57330f4155 to your computer and use it in GitHub Desktop.
<?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