不确定这是否是您想要的
$json = '[["1258765200","12350"],["1259370000","13000"],["1259974800","11840"],["1260579600","16359"],["1261184400","14230"],["1261789200","07406"],["1262394000","12846"],["1262998800","11204"],["1263603600","10234"]]';
$json = json_decode ( $json, true );
$values = array ();
foreach ( $json as $value ) {
$values [] = $value [1]; // Get Values
}
$median = median ( $values );
$sd = stddev ( $values );
$percentage = ($sd / $median) * 100;
$benchmark = 95 / 100;
if($percentage > $benchmark)
{
echo "outside 1 standard deviation (95%)";
}
输出
outside 1 standard deviation (95%)
职能
function stddev($array) {
$n = 0;
$mean = 0;
$M2 = 0;
foreach ( $array as $x ) {
$n ++;
$delta = $x - $mean;
$mean = $mean + $delta / $n;
$M2 = $M2 + $delta * ($x - $mean);
}
$variance = $M2 / ($n - 1);
return sqrt ( $variance );
}
function median($arr) {
sort($arr);
$count = count($arr); //total numbers in array
$middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
if($count % 2) { // odd number, middle is the median
$median = $arr[$middleval];
} else { // even number, calculate avg of 2 medians
$low = $arr[$middleval];
$high = $arr[$middleval+1];
$median = (($low+$high)/2);
}
return $median;
}