PhP how to calculate moments with variables rows
PHP Snippet 1:
$var1 = 0; $var2 = 0; $count = 0;
foreach($arr as $k=>$v){
if(is_numeric($v[0]) && is_numeric($v[1])){
$var2 += $v[0] * $v[1];
$var1 += $var2 * ($k + 1);
$count++;
}
}
$result = $var1 / $var2;
echo 'Result: ' . $result . '<br /> Count: ' . $count;