In order to find the average of all values in a map in PHP, you can use the array_sum()
function to sum all the values of the map, and then divide by the number of values using the count()
function. Here's an example:
main.php161 chars6 lines
In the above example, we have a map with three key-value pairs. We calculate the sum of all the values using array_sum()
, and count the number of values using count()
. We then calculate the average by dividing the sum by the count, and finally, print the result using echo
.
gistlibby LogSnag