I’m making a program that tracks hundreds of users, grabs their experience (stores it), and then grabs it again on demand once the designated time for tracking is over. What I’m trying to do is sort the amount of gained experience, while keeping it in association with the name, and then outputting the experience gained from highest to lowest.
Here’s an example of what I’m doing:
display();
function display() {
$participants = array("a", "b", "c", "d", "e");
sort($participants);
for ($i = 0; $i < count($participants); $i++) {
$starting = getStarting($participants[$i]);
$ending = getEnding($participants[$i]);
$gained = $ending - $starting;
}
}
function getStarting($name) {
$a = "a";
return $name == $a ? 304 : 4;
}
function getEnding($name) {
$a = "a";
return $name == $a ? 23 : 34;
}
So, I’m trying to make it so that if I were to print a variable, then ‘a’ would be first (because, as you can see, I made it so ‘a’ is the only ‘person’ that has gained more experience than the others’), then ‘b-e’ would follow it, alphabetically. It currently sorts it alphabetically before any data is collected, so I’m assuming all I’ll have to do is sort the gained experience.
How could I achieve this?
The easiest way would probably be to put the values into a multidimensional array, then use usort():