I have the following data in the following order(product_name -> stars):
Product 1 -> 5
Product 2 -> 4
Product 3 -> 3
Product 4 -> 2
Product 5 -> 3
Now, I want to calculate the average rating of each given rating. For eg: Average Rating of 5 stars and so on...
I tried the following for five stars:
$star = 0;
foreach($rates as $rate) {
$star = $star + $rate->stars
}
$avg = $star / count($rates);
return $avg;
The result is 5. Now if I multiply it will 100, then it becomes 500%
. I want it to be under 100%. Please help!