• 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 insert data from multiple select dropdown values into database?

Apply filter array/return terms

Laravel Collections. Is there some kind of assertStructure method?

how to remove white space in select 2

Handle error for duplicate entries - PHP/MySQL

Laravel 5 session not persisting after user is logged in

How to validate Envato Purchase Code in PHP

PHP: How to quickly split a key=value file into associative array

Return multiple values from a function using mysqli_fetch_assoc [closed]

Docker & Laravel : configure: error: Package requirements (oniguruma) were not met

Elasticsearch - Want to sort by field in all indices where that particular field available or not if not then avoid it

array_map triple dimensional array [duplicate]

Sort multidimensional array by column value within a column

Adding multiple items to WooCommerce cart at once

Laravel php artisan serve to mimic HTTPS

About Contact Privacy policy Terms and conditions