• 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

Make Shipping Method fields Mandatory on Woocommerce checkout page

merging two arrays with specified index

Chunk and transpose a flat array into rows with a specific number of columns

Use same method for inertia response and json response Laravel Jetstream

How to use React Router with Laravel?

PHP Slim Framework request using withAttribute error

Laravel Unknown Column 'updated_at'

Sum column values from multiple arrays

Additional price based on cart item count in WooCommerce

How to auto populate preferredCountries from intl-tel-input with db output

Required field only if another field has a value, must be empty otherwise

Getting error: CodeIgniterDatabaseBaseResult::getResult in CodeIgniter

Multiply each value in array using array_map function

Transfer data between JavaScript and PHP through JSON

Query Optimization, changing the queries in the loop into a single processing query

About Contact Privacy policy Terms and conditions