arrays - Foreach loop and average in PHP -


i'm rather new programming in general. i'm starting off exercises i'm kind of getting stuck. created array , looped thru foreach loop print out each individual number stored in array, dont know find average of numbers , print out.

<?php  $myarray = array(87,75,93,95);  foreach($myarray $value){     echo "$value <br>"; }  ?> 

you could:

$avg = array_sum($myarray) / count($myarray); echo $avg; 

where:

  • array_sum calculates sum of elements in given array.
  • count outputs total number of elements in given array.

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -