This question already has an answer here:
- How to sort an array of arrays in php? 2 answers
Given the following example:
$user1 = array('username' => 'test1', 'score' => 2000, 'someotherdata' => 1.0);
$user2 = array('username' => 'test2', 'score' => 4325, 'someotherdata' => 2.0);
$user3 = array('username' => 'test3', 'score' => 624534, 'someotherdata' => 3.0);
$user4 = array('username' => 'test4', 'score' => 564, 'someotherdata' => 1.4);
$user5 = array('username' => 'test5', 'score' => 34256, 'someotherdata' => 1.5);
$user6 = array('username' => 'test6', 'score' => 5476, 'someotherdata' => 1.8);
$arr = array($user1, $user2, $user3, $user4, $user5, $user6);
How would I be able to sort $arr
by the field score
nicely in PHP 7? I got a working bubblesort I made my own, but is there a way to use builtin PHP 7 features to do it nicely, as bubblesort is pretty expensive (I could do a Quicksort on my own, but before I do that I wanted to know if there is a better way).
</div>