• 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 find the date a user created their Google account

PHP: remove filename from path

I need to link Google Sheet with my Laravel

Smarty if isset

How to get multiple values with same key from an array PHP

dompdf and img tag, image wont show

phpunit - testing is painfully slow

Comma separated list from array with "and" before last element

CodeIgniter 4: Like and Dislike Functionality

how to insert data into select2 search input after scan using qrcode

Xdebug in Laravel is not working with VSCode

How to get an Array value inside an object in an array Php [duplicate]

OAuth2 Token PHP

JSON Render Issue in Date Object Laravel and PHP 7.4

Call authenticate manually in router middleware

About Contact Privacy policy Terms and conditions