• 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

Transpose csv file data [duplicate]

Multiple order by in WooCommerce

SMTP ERROR: MAIL FROM command failed: 530 5.7.0 Must issue a STARTTLS command first when using PHPMailer

str_word_count() function doesn't display Arabic language properly

display WooCommerce “Add to cart” button with short-code [add_to_cart ] dynamically

How to create a scheduler application in php

Webscraping Symfony/Panther: Can't get HTML

How to test laravel controller method?

mysql_result is defined but mysql_free_result warns it expected a resource

Why is this PHP array not the same?

How do I enable error reporting in Laravel?

PHP drop down list using array's and foreach (else and for) code

Symfony Error: "An exception has been thrown during the rendering of a template"

Laravel: Create morphs() relationship nullable

Results page in other window

About Contact Privacy policy Terms and conditions