• 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

Combine array with same value and add other [duplicate]

phparrays


PHP Snippet 1:

foreach($data as $key => $elem) {
    if (!isset($result[$elem["date"]])) {
        $result[$elem["date"]] = $elem;
    } else {
        $result[$elem["date"]]["count"] += $elem['count'];
        $result[$elem["date"]]["audio_click"] += $elem['audio_click'];
    }
}
$result = array_values($result); // optional

Related Snippets

Dropdown with current value from Mysql

How to remove Deprecated SymfonyComponentDebugDebugClassLoader?

php code to send checkbox form results to email

Convert date and time to Jalali in Laravel

PHP block shortcut in Visual Studio Code

I cannot create a auto generated date time in mysql workbench

How to average columns of data from multiple, flat arrays?

How to disable widget block editor of WordPress?

Sum array values

PHP7 CLI attempts to load xdebug twice - "Cannot load Xdebug - it was already loaded"

PHP returning an error message and false

Implode columnar values between two arrays into a flat array of concatenated strings

selected value from the listbox in php

Unable to uninstall brew php from homebrew

Attempted to call an undefined method named "get" of class "MailController"

About Contact Privacy policy Terms and conditions