• 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

Show rotation of tweets using current day of month

Reading input in php from terminal

Sum array values of a column within each column of an array with 3 levels

Set quantity minimum, maximum and step at product level in Woocommerce

PHPUnit 7: Failed asserting that exception of type InvalidArgumentException is thrown

How to to send mail using gmail in Laravel?

Laravel Nova, route not found

(Cache::lock()) -> get() -- Under what conditions does it return false?

How to fix " Uncaught TypeError: Argument 1 passed to JpGraphException::defaultHandler() " problem in php 7.1.3 and jpgraph 4.2.6?

Remove categories with all childs derived from parent category

Unable to match results of php hash_hmac() and coldfusion hmac()

Ajax GET request fails in laravel 8

Add 2 Webcam in one page with WebcamJS

SQL to convert multiple rows into a single row of variable length

Star and Half Star Rating in Laravel

About Contact Privacy policy Terms and conditions