fork download
  1. <?php
  2.  
  3. $Turma = array(
  4.  
  5. array("nome" => "Diogo", "score" => "100", "time" => "6" ),
  6. array("nome" => "Joao","score" => "500", "time" => "3" ),
  7. array("nome" => "Miguel", "score" => "125", "time" => "8" ),
  8. array("nome" => "Daniela", "score" => "105", "time" => "7" ),
  9. array("nome" => "Joana", "score" => "100", "time" => "6" ),
  10. array("nome" => "Diogo", "score" => "275", "time" => "4" ),
  11. array("nome" => "Francisco", "score" => "300", "time" => "9" ),
  12. array("nome" => "Ines", "score" => "650", "time" => "2" ),
  13. array("nome" => "Dionisio", "score" => "101", "time" => "10" ),
  14. array("nome" => "Ricardo", "score" => "200", "time" => "8" ),
  15. array("nome" => "Fabio", "score" => "201", "time" => "11" ),
  16. array("nome" => "Tiago","score" => "50", "time" => "13" ),
  17. array("nome" => "Carolina", "score" => "150", "time" => "5" ),
  18. array("nome" => "Rui", "score" => "130", "time" => "3" ),
  19. array("nome" => "Luisa", "score" => "1000", "time" => "1" ),
  20.  
  21. );
  22.  
  23.  
  24.  
  25.  
  26.  
  27. usort($Turma, function ($a, $b) {
  28.  
  29. $resultado = $b['score'] <=> $a['score'];
  30.  
  31. return $resultado === 0 ? $b['time'] <=> $b['time'] : $resultado;
  32. });
  33.  
  34. print_r($Turma);
Success #stdin #stdout 0.03s 24352KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [nome] => Luisa
            [score] => 1000
            [time] => 1
        )

    [1] => Array
        (
            [nome] => Ines
            [score] => 650
            [time] => 2
        )

    [2] => Array
        (
            [nome] => Joao
            [score] => 500
            [time] => 3
        )

    [3] => Array
        (
            [nome] => Francisco
            [score] => 300
            [time] => 9
        )

    [4] => Array
        (
            [nome] => Diogo
            [score] => 275
            [time] => 4
        )

    [5] => Array
        (
            [nome] => Fabio
            [score] => 201
            [time] => 11
        )

    [6] => Array
        (
            [nome] => Ricardo
            [score] => 200
            [time] => 8
        )

    [7] => Array
        (
            [nome] => Carolina
            [score] => 150
            [time] => 5
        )

    [8] => Array
        (
            [nome] => Rui
            [score] => 130
            [time] => 3
        )

    [9] => Array
        (
            [nome] => Miguel
            [score] => 125
            [time] => 8
        )

    [10] => Array
        (
            [nome] => Daniela
            [score] => 105
            [time] => 7
        )

    [11] => Array
        (
            [nome] => Dionisio
            [score] => 101
            [time] => 10
        )

    [12] => Array
        (
            [nome] => Diogo
            [score] => 100
            [time] => 6
        )

    [13] => Array
        (
            [nome] => Joana
            [score] => 100
            [time] => 6
        )

    [14] => Array
        (
            [nome] => Tiago
            [score] => 50
            [time] => 13
        )

)