• 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

Store / Website Column in Magento 2 Admin Grid - Custom Module

php 7 php.ini upload_max_filesize not working

Python - Include another Python script

Laravel websockets AWS EC2 - Connection failed

Symfony - EasyAdmin - Add and remove functions are ignored from AssociationField

Modify microseconds of a PHP DateTime object

Failed user login on production server using Symfony framework (Authentication request could not be processed due to...)

How can I get user id from session in javascript?

How do I call a php file with axios?

How to break out of a foreach once a condition is met?

Install mysql client in docker image

enable Apache http Authorization header

Parsing JSON File to array in PHP

Return multiple values from a function using mysqli_fetch_assoc [closed]

IlluminateDatabaseQueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project

About Contact Privacy policy Terms and conditions