fork download
  1. <?php
  2.  
  3. $person[] = array(
  4. 'user' => "A",
  5. 'total' => 5,
  6. 'goal' => 12,
  7. 'dailycount' => 2
  8. );
  9.  
  10. $person[] = array(
  11. 'user' => "B",
  12. 'total' => 1,
  13. 'goal' => 12,
  14. 'dailycount' => 2
  15. );
  16. $person[] = array(
  17. 'user' => "C",
  18. 'total' => 3,
  19. 'goal' => 12,
  20. 'dailycount' => 2
  21. );
  22. echo "Descending\n";
  23. array_multisort(array_column($person, 'total'), SORT_DESC, $person);
  24. print_r($person);
  25. echo "Ascending\n";
  26. array_multisort(array_column($person, 'total'), SORT_ASC, $person);
  27. print_r($person);
Success #stdin #stdout 0s 82560KB
stdin
Standard input is empty
stdout
Descending
Array
(
    [0] => Array
        (
            [user] => A
            [total] => 5
            [goal] => 12
            [dailycount] => 2
        )

    [1] => Array
        (
            [user] => C
            [total] => 3
            [goal] => 12
            [dailycount] => 2
        )

    [2] => Array
        (
            [user] => B
            [total] => 1
            [goal] => 12
            [dailycount] => 2
        )

)
Ascending
Array
(
    [0] => Array
        (
            [user] => B
            [total] => 1
            [goal] => 12
            [dailycount] => 2
        )

    [1] => Array
        (
            [user] => C
            [total] => 3
            [goal] => 12
            [dailycount] => 2
        )

    [2] => Array
        (
            [user] => A
            [total] => 5
            [goal] => 12
            [dailycount] => 2
        )

)