How do you work out the average and the total of array elements in php using a for loop?

jassie

New member
This is my code so far... (i know its not correct)

<?php

$vals = array (2, 4, 6, 8);

$count = count($vals);

for($i=0; $i<$count; $++){

$average = $vals/$count;

echo $average;

?>
 
Back
Top