I'm trying to achieve a list of ordered score points a user received and the number of times he received each score using the array that comes from the database $user_rating_points. The base score values are defined as an array of possible points $score_points.
Imagining that the query for a user gives me the following array for his given points:
// The base score points' scale
$score_points = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
// The array of points a user received (from the database query)
$user_rating_points = [1, 3, 2, 7, 3, 4, 9, 2, 10, 6, 1, 7, 10, 8, 4, 8, 9, 4, 7, 10, 5];
I want to achieve something like the following:
- 1 point: 3 times
- 2 points: 2 times
- 3 points: 5 times
- ...
- 9 points: 2 times
- 10 points: 3 times
I've tried using the array_count_values($user_rating_points) with sort($user_rating_points); but either on a HTML ul or a print_r($user_rating_points) I'm unable to get a list like the above example.
Thanks in advance for any help on this issue that is probably much simpler to solve than I expect, yet it seems like I've gone into a loop and not finding a solution.
"what you want to achieve"suggests there are 3 of #1 in$user_rating_pointsyet I can see only 2. The same for #3 where I can see only 2. Is that just dummy data or some other criteria I've missed?$user_rating_pointsas it was awarded 3 times? The same for the other numbers? ie10 pointsawarded 3 times so will appear 3 times in$user_rating_points?array_count_valueswill give you so I'm confused why you think otherwise. Looking at the arrays given there is a discrepancy with what you want and what the arrays contain. Are thewhat you wantexamples accurately based upon the arrays given here or justfor example??