• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

PhP how to calculate moments with variables rows

phparraysjson


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;

Related Snippets

Python - Include another Python script

Group data in a multidimensional array based on two columns

PHPS source file - 403 Forbidden You don't have permission to access this resource

How to assert parameter attribute sub-structures in PHPUnit mock call expectations

PHP contact form configuration [duplicate]

Laravel Command Schedule Not Working Properly

How to average columns of data from multiple, flat arrays?

How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

How to override header set in Apache config with more specific header in a virtual host

I want to store data in new index as per my key in php [duplicate]

Yii2: How do I debug console commands?

Woocommerce Checkout - Add conditional field required if one field is filled

php mysql + create a friend request system

Required field only if another field has a value, must be empty otherwise

Laravel database insert with combining array and string

About Contact Privacy policy Terms and conditions