• 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

Using if(isset($_POST['submit'])) to not display echo when script is open is not working

Dropdown with current value from Mysql

Laravel Route issues with Route order in web.php

Update Order custom Field value with WooCommerce REST API

Laravel: HTML in notification

laravel 5.6 bulk inserting json data

How can I access an array/object?

Laravel insert dynamic input values with radio button

Eloquent insert id with sequence next value

I cannot create a auto generated date time in mysql workbench

Search for array row with specific column value and return another value from qualifying row

Laravel implode array items to new lines

Phalcon: setStatusCode returns empty response

How avoid Moved Permanently The document has moved here

Sum array values

About Contact Privacy policy Terms and conditions