• 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 do I get friend list from Friends table with counts of friends of my friends

Laravel Database Strict Mode

Distribute array row data to make multiple new rows

Limit WooCommerce products in cart only from one custom taxonomy

Laravel 5: Is there a non-case sensitive way to sort a collection by an attribute?

Passing PHP JSON to Javascript: echo json_encode vs echo json declaration

Split a string array into pieces

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

Trying to iterate over a mongodb cursor twice - failing

Adding hreflang tags automatically in WordPress subdirectory multisite

Google Gmail API - How to login programatically?

PHP each() function replacement

How can I make Laravel return a custom error for a JSON REST API

Send POST data via raw JSON with Postman

How to Install Composer Require doctrine/dbal

About Contact Privacy policy Terms and conditions