• 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

Laravel: Create morphs() relationship nullable

Make Shipping Method fields Mandatory on Woocommerce checkout page

Show Custom Data in Woocommerce Order Details Admin Area

Convert regular text to array using notepad++

Laravel - Browser displays message again when I press back button

Woocommerce product attributes with hierarchy like categories

How to modify CSS in a specific page of the WP admin dashboard (backend)

What is my SQL missing?

how to loop through json response data using ajax jquery?

How to loop a tree array with unknown depth and get array blocks?

Symfony run hint kernel.secret parameter not found

Laravel 5 controller sending JSON integer as string

How to create a individual template for page or post in custom plugin?

Call to a member function fetch_field() on a non-object MySQLiDB

PHP array stringify

About Contact Privacy policy Terms and conditions