I'm trying to perform a Standard Deviation with PHP.
I used this function I founded there because the stats_standard_deviation doesn't seem to be reliable
<?php
class TestController extends \BaseController {
function MyFunction() {
$array = array('1','2','3','4');
function sd_square($x, $mean) { return pow($x - $mean,2); }
function sd($array) {
return sqrt(array_sum(array_map("sd_square", $array, array_fill(0,count($array), (array_sum($array) / count($array)) ) ) ) / (count($array)) );
}
} return sd($array)
} ?>
The problem is that it returns me array_map() expects parameter 1 to be a valid callback, function 'sd_square' not found or invalid function name
when I try to use it.
Looking at some post here I tried to change "sd_square"
for "self::sd_square"
or array($this, "sq_square")
.
This kind of sidesteps the issue (and you should address it), but
sq_square
is small enough you may want to consider simply inliningChange:
To:
Or: