• 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

generating a random code in php?

Apply filter array/return terms

wordpress : How to specify the cause "This site can’t be reached"

How do I call a php file with axios?

How to get rid of ampersand using WP Nonce URL and WP Redirect or PHP header

Is there an equivalent of DynamoDB on Azure as a PHP session Handler

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

How to set time with DateTime modify?

Change user role if checkout custom checkbox is checked in WooCommerce

How to add a heading in between checkout fields of WooCommerce

User pool client {id}does not exist

Calculating Median of an array in PHP

Laravel Excel::store file empty after stored

calling server using nusoap with complextype

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

About Contact Privacy policy Terms and conditions