• 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: HTML in notification

How can I make this nested location configuration use the correct path to call a php program?

PHP Print to Network Printer

How to install php_imagick on wamp64

How to show selected value using javascript in laravel

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in

Change user role if checkout custom checkbox is checked in WooCommerce

array_map triple dimensional array [duplicate]

Log a user out of a website when they put their computer to sleep

Why do I have invalid argument supply for foreach in Laravel for json response? [duplicate]

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

How do I set the maximum php memory limit

How to redirect to another page and call a Function there on Angular ng-click

How to send image,audio or video through the WhatsApp API - PHP

Shopify password update using Shopify API

About Contact Privacy policy Terms and conditions