fork download
  1. <?php
  2. $linhas = array(
  3. "T3497012@CHOSTBRHDDSB@EICM_BORA@BPHS@Bamz",
  4. "T3497012@BHOSTBRHDDSB@EICM_BORA@BPHS@Bamz",
  5. "T3497012@AHOSTBRHDDSB@EICM_BORA@BPHS@Bamz",
  6. "T3497012@AHOSTBRHDDSB@EICM_BORB@BPHS@Aama",
  7. "T3497012@AHOSTBRHDDSB@EICM_BORC@APHS@cama",
  8. "T2497123@DHOSTBRHDDSB@CICM_BORD@APHS@camb",
  9. "T2497123@EHOSTBRHDDSB@BICM_BORE@APHS@camc",
  10. "T5557012@FHOSTBRHDDSB@AICM_BORF@APHS@camd"
  11. );
  12.  
  13. $i = 1;
  14. for ($i = 0; $i < (count($linhas) - 1); $i++){
  15. $linhai = explode("@", $linhas[$i]);
  16. for ($j = $i + 1; $j < count($linhas); $j++){
  17. $linhaj = explode("@", $linhas[$j]);
  18.  
  19. $troca = false;
  20. if ($linhai[2] > $linhaj[2])
  21. $troca = true;
  22. else if (($linhai[2] == $linhaj[2]) && ($linhai[3] > $linhaj[3]))
  23. $troca = true;
  24. else if (($linhai[2] == $linhaj[2]) && ($linhai[3] == $linhaj[3]) && ($linhai[4] > $linhaj[4]))
  25. $troca = true;
  26. else if (($linhai[2] == $linhaj[2]) && ($linhai[3] == $linhaj[3]) && ($linhai[4] == $linhaj[4]) && ($linhai[1] > $linhaj[1]))
  27. $troca = true;
  28.  
  29. if ($troca){
  30. $suporte = $linhas[$i];
  31. $linhas[$i] = $linhas[$j];
  32. $linhas[$j] = $suporte;
  33. }
  34. }
  35. }
  36. var_dump($linhas);
  37. ?>
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
array(8) {
  [0]=>
  string(41) "T5557012@FHOSTBRHDDSB@AICM_BORF@APHS@camd"
  [1]=>
  string(41) "T2497123@EHOSTBRHDDSB@BICM_BORE@APHS@camc"
  [2]=>
  string(41) "T2497123@DHOSTBRHDDSB@CICM_BORD@APHS@camb"
  [3]=>
  string(41) "T3497012@AHOSTBRHDDSB@EICM_BORA@BPHS@Bamz"
  [4]=>
  string(41) "T3497012@BHOSTBRHDDSB@EICM_BORA@BPHS@Bamz"
  [5]=>
  string(41) "T3497012@CHOSTBRHDDSB@EICM_BORA@BPHS@Bamz"
  [6]=>
  string(41) "T3497012@AHOSTBRHDDSB@EICM_BORB@BPHS@Aama"
  [7]=>
  string(41) "T3497012@AHOSTBRHDDSB@EICM_BORC@APHS@cama"
}