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