fork(2) download
  1. <?php
  2. $org = array('1', '2', '2', '3', '3', '4', '5', '6');
  3.  
  4. // simple array unique call with sort by string
  5. $new = array_unique($org, SORT_STRING);
  6.  
  7. // output the sorted array
  8. var_dump($new);
  9. echo "";
  10.  
  11. // empty sorted array
  12. $new = array();
  13. var_dump($new);
  14. echo "";
  15.  
  16. // sort with in_array()
  17. for ($i=0; $i < count($org); $i++) {
  18.  
  19. if (!in_array($org[$i], $new)) {
  20. $new[] = $org[$i];
  21. }
  22. }
  23.  
  24. // output the sorted array
  25. var_dump($new);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
array(6) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "2"
  [3]=>
  string(1) "3"
  [5]=>
  string(1) "4"
  [6]=>
  string(1) "5"
  [7]=>
  string(1) "6"
}
array(0) {
}
array(6) {
  [0]=>
  string(1) "1"
  [1]=>
  string(1) "2"
  [2]=>
  string(1) "3"
  [3]=>
  string(1) "4"
  [4]=>
  string(1) "5"
  [5]=>
  string(1) "6"
}