• 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

How to fix bootstrap multiselect search data using ajax

PHP -> Next nearest date defined by array of days in week

Laravel Sanctum CSRF not authenticating

500 (Internal Server Error) with Laravel & Docker [duplicate]

How to programmatically find public properties of a class from inside one of it's methods

how to sort by a custom appended relation to model

If action is on a different page do I use fwrite function

PHP password_verify

How to implement placeholder in a php file for moodle plugin?

Call to undefined function openssl_decrypt

Send same name multiple checkbox values via ajax

Zig-zag scan an N x N array

Laravel get user data with profile

GA4 custom event from server side, can someone tell me how i can do the following code in php?

Assign output of PHP function to a variable

About Contact Privacy policy Terms and conditions