• 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

Laravel Collections. Is there some kind of assertStructure method?

Php - Sum up the numbers in an array one by one

Return multiple values from a function using mysqli_fetch_assoc [closed]

JQuery content editable div and text box on submit not sending POST

add uri parameter to Route name in laravel

Comma separated list from array with "and" before last element

Printing more than one array using print_r or any other function in php

Google API Heatmap Layer exception, why?

Laravel 4 Redirect::back() not going to previous page (refreshing current page)

Change user role if checkout custom checkbox is checked in WooCommerce

Where do I need to place a hook for phpunit?

NGINX: connect() to unix:/var/run/php7.2-fpm.sock failed (2: No such file or directory)

Combine multiple columns into an array as one of the key in a results set

Laravel 5.5 change unauthenticated login redirect url

how to youtube api data to print in toolset metabox using a button click before save-post

About Contact Privacy policy Terms and conditions