3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 0 => [ "platform"=> "Google", "positive"=> "10", "negative"=> "5", "blocked"=> "1", ], 1 => [ "platform"=> "Yandex", "positive"=> "6", "negative"=> "2", "blocked"=> "1", ], 2 => [ "platform"=> "Google", "positive"=> "15", "negative"=> "35", "blocked"=> "23", ] ]; $result = array_values(array_reduce($array, function($carry, $item) { foreach($item as $k => $v) { if (isset($carry[$item['platform']][$k])) { if (is_numeric($v)) $carry[$item['platform']][$k] += $v; } else $carry[$item['platform']][$k] = $v; } return $carry; }, [])); print_r($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ZJu8B
function name:  (null)
number of ops:  15
compiled vars:  !0 = $array, !1 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   24     1        INIT_FCALL                                               'array_values'
          2        INIT_FCALL                                               'array_reduce'
          3        SEND_VAR                                                 !0
          4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FZJu8B%3A24%240'
   33     5        SEND_VAL                                                 ~3
          6        SEND_VAL                                                 <array>
          7        DO_ICALL                                         $4      
          8        SEND_VAR                                                 $4
          9        DO_ICALL                                         $5      
   24    10        ASSIGN                                                   !1, $5
   35    11        INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FZJu8B%3A24%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 23
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 23
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 17
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/ZJu8B
function name:  {closure}
number of ops:  26
compiled vars:  !0 = $carry, !1 = $item, !2 = $v, !3 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2      > FE_RESET_R                                       $4      !1, ->23
          3    > > FE_FETCH_R                                       ~5      $4, !2, ->23
          4    >   ASSIGN                                                   !3, ~5
   26     5        FETCH_DIM_R                                      ~7      !1, 'platform'
          6        FETCH_DIM_IS                                     ~8      !0, ~7
          7        ISSET_ISEMPTY_DIM_OBJ                         0          ~8, !3
          8      > JMPZ                                                     ~9, ->18
   27     9    >   INIT_FCALL                                               'is_numeric'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                         $10     
         12      > JMPZ                                                     $10, ->17
         13    >   FETCH_DIM_R                                      ~11     !1, 'platform'
         14        FETCH_DIM_RW                                     $12     !0, ~11
         15        ASSIGN_DIM_OP                +=               1          $12, !3
         16        OP_DATA                                                  !2
         17    > > JMP                                                      ->22
   29    18    >   FETCH_DIM_R                                      ~14     !1, 'platform'
         19        FETCH_DIM_W                                      $15     !0, ~14
         20        ASSIGN_DIM                                               $15, !3
         21        OP_DATA                                                  !2
   25    22    > > JMP                                                      ->3
         23    >   FE_FREE                                                  $4
   32    24      > RETURN                                                   !0
   33    25*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FZJu8B%3A24%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
131.14 ms | 1405 KiB | 21 Q