PHP Sort by descending order: There are 6 values on textboxes. I need to sort to
ID: 3687687 • Letter: P
Question
PHP Sort by descending order: There are 6 values on textboxes. I need to sort top 5 values on descending order and drop lowest value. Also, I am trying to figure out how to have percentage sign (%) after average:
My current code:
Currently its doing:
Expected it to do:
action Enter Quiz Scores: Quiz 1: " autofocus>% $scores [1]; ?>">K/1abel> $scores [2]; ?>">K/1abel> $scores [3]; ?>">K/1abel> $scores [4];?>">K/1abel> $scores [5];?>">K/1abel> Quiz Average :'; for (SarrayIndex-0; $array!ndexExplanation / Answer
rsort($scores);
// It prints 6 elements in reverse order only.
So take those sorted 6 elements from rsort() function then use array_slice method to print top 5 elements.
$printTopFive = array_slice($scores, 0, 5);
// Which gives you top five sorted elements from the array.
-------------------------------------------------------------------------------------------------------
For displaying (%) percentage sysmbol after the average place. consider the below
echo '<p>' .number_format($Average, 2) . letterGrade($Average). '%' '</p>';
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.