• 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

PHPExcel export HTML table to xlsx

Zig-zag scan an N x N array

woocommerce get_order_report_data to show order_item_id

str_replace or preg_replace random number from string

Unit (real unit test) of test laravel relationship

Laravel/ PHP: Order By Alphabetical with numbers in order [duplicate]

selected value from the listbox in php

Laravel 5.2: Unable to locate factory with name [default]

Laravel Database Strict Mode

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

Warning file_get_contents () failed to open stream: HTTP request failed! HTTP/1.0 402 Payment Required

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

Laravel Sanctum CSRF not authenticating

is there any way to validate a field that sometime is File(image) && sometime is String(Src of same image)

Required field only if another field has a value, must be empty otherwise

About Contact Privacy policy Terms and conditions