• 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

PHP code for generating decent-looking coupon codes (mix of letters and numbers)

How to update array value in Laravel

Implode array with array of glue strings

Show rotation of tweets using current day of month

how to pass row id in href of a tag in codeigniter controller?

How to use a PHP MVC Controller, one thats invoked by calling a URL, to call and execute more than one function? [duplicate]

Convert every two values of an associative array into key-value pairs

php echo xml documents with header

Creating a config file in PHP

Passing PHP JSON to Javascript: echo json_encode vs echo json declaration

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables 11 [closed]

merging two arrays with specified index

Phpunit partial mock + proxy Entity

Insert And Retrieve Data in MySQL with $.post Noob Question

How to identify whether webp image is static or animated?

About Contact Privacy policy Terms and conditions