To find the variance of all elements in an array in PHP, you can use the array_sum()
and pow()
functions in combination with the count()
function. The following function will calculate the variance of all elements in an array:
main.php223 chars10 lines
You can use this function like this:
main.php60 chars3 lines
This will output the variance of all elements in the array, which is 2.5
.
gistlibby LogSnag