• 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

Symfony Error: "An exception has been thrown during the rendering of a template"

Pass an image through AJAX [duplicate]

How to set dynamic `home` and `siteurl` in WordPress?

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'posts.post' doesn't exist

Symfony Make:Migration : The metadata storage is not up to date, please run the sync-metadata-storage command to fix this issue

Could not decode a text frame as UTF-8.

Lumen - Postgresql setup - Composer

How can I solve "laravel/horizon v1.1.0 requires ext-pcntl * -> the requested PHP extension pcntl is missing from your system"?

PhpSpreadSheet: How to save Workbook sheets in individual CSV files

Unable to create lockable file - Laravel 8 & PHP 8

how can I set a session variable in Drupal 8 and get it in a php script?

How to send image,audio or video through the WhatsApp API - PHP

php echo remove slashes from url [duplicate]

Fatal error: Array callback has to contain indices 0 and 1

Reload parent page after submit in iframe

About Contact Privacy policy Terms and conditions