fork download
  1. <?php
  2.  
  3. $array = [
  4. "T3497012@CHOSTBRHDDSB@EICM_BORA@BPHS@Bamz",
  5. "T3497012@BHOSTBRHDDSB@EICM_BORA@BPHS@Bamz",
  6. "T3497012@AHOSTBRHDDSB@EICM_BORA@BPHS@Bamz",
  7. "T3497012@AHOSTBRHDDSB@EICM_BORB@BPHS@Aama",
  8. "T3497012@AHOSTBRHDDSB@EICM_BORC@APHS@cama",
  9. "T2497123@DHOSTBRHDDSB@CICM_BORD@APHS@camb",
  10. "T2497123@EHOSTBRHDDSB@BICM_BORE@APHS@camc",
  11. "T5557012@FHOSTBRHDDSB@AICM_BORF@APHS@camd"
  12. ];
  13.  
  14. foreach ($array as $chave => $valor){
  15. $array[$chave] = explode("@",$valor);
  16. }
  17.  
  18. usort($array, function($a, $b){
  19.  
  20. if ($a[2] === $b[2]){
  21. if ($a[3] === $b[3]){
  22. if ($a[4] === $b[4]){
  23. return strcmp($a[1], $b[1]);
  24. }
  25. else return strcmp($a[4], $b[4]);
  26. }
  27. else return strcmp($a[3], $b[3]);
  28. }
  29. else return strcmp($a[2], $b[2]);
  30.  
  31. });
  32.  
  33.  
  34. foreach($array as $chave => $valor){
  35. $array[$chave] = implode("@", $array[$chave]);
  36. }
  37.  
  38. print_r($array);
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
Array
(
    [0] => T5557012@FHOSTBRHDDSB@AICM_BORF@APHS@camd
    [1] => T2497123@EHOSTBRHDDSB@BICM_BORE@APHS@camc
    [2] => T2497123@DHOSTBRHDDSB@CICM_BORD@APHS@camb
    [3] => T3497012@AHOSTBRHDDSB@EICM_BORA@BPHS@Bamz
    [4] => T3497012@BHOSTBRHDDSB@EICM_BORA@BPHS@Bamz
    [5] => T3497012@CHOSTBRHDDSB@EICM_BORA@BPHS@Bamz
    [6] => T3497012@AHOSTBRHDDSB@EICM_BORB@BPHS@Aama
    [7] => T3497012@AHOSTBRHDDSB@EICM_BORC@APHS@cama
)