• 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

How to get the ID of the link in another page in php

Vimeo API: how to save a vimeo into a subfolder?

How to convert binary string to normal string in php

how to prevent float variables displaying as scientific notation when printing [duplicate]

How to fix bootstrap multiselect search data using ajax

how to hide previous markers when new markers added in google map javascript api

Filter WooCommerce related products by Polylang language

Laravel You requested 1 items, but there are only 0 items available

Laravel phpunit test failing authorization

jwt decode throws Invalid argument supplied for foreach() on php-jwt and codeignitor 4

Add custom text under order details on WooCommerce My account view order pages

Do I need to install `fxp/composer-asset-plugin` if I'm not doing front-end development

Limit of log line written to Apache Errorlog from mod php error_log

PHP: set a (deep) array key from an array [closed]

Mysqli Output to a table

About Contact Privacy policy Terms and conditions