3v4l.org

run code in 300+ PHP versions simultaneously
<?php $langs = [ 5 => "english", 10 => "french", 12 => "german" ]; $posts = [ [ "date" => "13-07-2022", "lang_id" => 5, "amount" => 90, ], [ "date" => "13-07-2022", "lang_id" => 10, "amount" => 34, ], [ "date" => "14-07-2022", "lang_id" => 5, "amount" => 7, ], ]; $defaults = array_fill_keys($langs, 0); $result = []; foreach ($posts as $row) { extract($row); $result[$date] ??= ['date' => $date] + $defaults; $result[$date][$langs[$lang_id]] += $amount; } var_export(array_values($result));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 26
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 26
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/Run1r
function name:  (null)
number of ops:  34
compiled vars:  !0 = $langs, !1 = $posts, !2 = $defaults, !3 = $result, !4 = $row, !5 = $date, !6 = $lang_id, !7 = $amount
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, <array>
   27     2        INIT_FCALL                                               'array_fill_keys'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 0
          5        DO_ICALL                                         $10     
          6        ASSIGN                                                   !2, $10
   28     7        ASSIGN                                                   !3, <array>
   29     8      > FE_RESET_R                                       $13     !1, ->26
          9    > > FE_FETCH_R                                               $13, !4, ->26
   30    10    >   INIT_FCALL                                               'extract'
         11        SEND_REF                                                 !4
         12        DO_ICALL                                                 
   31    13        FETCH_DIM_IS                                     ~15     !3, !5
         14        COALESCE                                         ~16     ~15
         15        INIT_ARRAY                                       ~17     !5, 'date'
         16        ADD                                              ~18     ~17, !2
         17        ASSIGN_DIM                                       ~19     !3, !5
         18        OP_DATA                                                  ~18
         19        QM_ASSIGN                                        ~16     ~19
         20        FREE                                                     ~16
   32    21        FETCH_DIM_R                                      ~21     !0, !6
         22        FETCH_DIM_RW                                     $20     !3, !5
         23        ASSIGN_DIM_OP                +=               1          $20, ~21
         24        OP_DATA                                                  !7
   29    25      > JMP                                                      ->9
         26    >   FE_FREE                                                  $13
   34    27        INIT_FCALL                                               'var_export'
         28        INIT_FCALL                                               'array_values'
         29        SEND_VAR                                                 !3
         30        DO_ICALL                                         $23     
         31        SEND_VAR                                                 $23
         32        DO_ICALL                                                 
         33      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.07 ms | 1009 KiB | 17 Q