you can use this code for sum array value using php . First assign variable shich store all sum value so this must set 0 and use loop for make all value sum. this is your code which help you and if your array $your_array then
$sum = 0; // this is store all sum value so first assign 0
foreach ($your_array as $rating) {
{
$sum += $rating->rating; // sum value with previous value and store it and no need to convert string type to int cause php do it
}
echo $sum; // this is final value
echo $total_sum = $sum / 5; // this is your desire result
and if your array is associative then use this code
$sum = 0; // this is store all sum value so first assign 0
foreach ($your_array as $rating) {
{
$sum += $rating['rating']; // sum value with previous value and store it and no need to convert string type to int cause php do it
}
echo $sum; // this is final value
echo $total_sum = $sum / 5; // this is your desire result
check this code and hope it will help you .
foreach()& extract all the element's value & calculate the Sum. Then divide by 5. Ref - php.net/manual/en/control-structures.foreach.php