3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data = [ ['id' => 1, 'date_inserted' => '2020-09-06', 'marketplace' => 'Etsy', 'total_stickers' => 11, 'total_orders' => 8, 'total_value' => 41.619999999999997], ['id' => 2, 'date_inserted' => '2020-09-06', 'marketplace' => 'Woo', 'total_stickers' => 2, 'total_orders' => 1, 'total_value' => 7.9800000000000004], ['id' => 3, 'date_inserted' => '2020-09-06', 'marketplace' => 'eBay', 'total_stickers' => 44, 'total_orders' => 40, 'total_value' => 115.63], ['id' => 4, 'date_inserted' => '2020-09-07', 'marketplace' => 'Etsy', 'total_stickers' => 8, 'total_orders' => 4, 'total_value' => 34.920000000000002], ['id' => 5, 'date_inserted' => '2020-09-07', 'marketplace' => 'Woo', 'total_stickers' => 9, 'total_orders' => 3, 'total_value' => '52.90'], ['id' => 6, 'date_inserted' => '2020-09-07', 'marketplace' => 'eBay', 'total_stickers' => 23, 'total_orders' => 21, 'total_value' => 58.030000000000001] ]; $result = []; foreach (array_column($data, 'date_inserted') as $date) { foreach (array_filter($data, function($v) use ($date) { return $v['date_inserted'] === $date; }) as $item) { $result[$date][$item['marketplace']] = [ 'id' => $item['id'], 'total_stickers' => $item['total_stickers'], 'total_orders' => $item['total_orders'], 'total_value' => $item['total_value'] ]; } } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 31
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 31
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 29
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 29
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 29
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
filename:       /in/QnHQf
function name:  (null)
number of ops:  36
compiled vars:  !0 = $data, !1 = $result, !2 = $date, !3 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   11     1        ASSIGN                                                       !1, <array>
   12     2        INIT_FCALL                                                   'array_column'
          3        SEND_VAR                                                     !0
          4        SEND_VAL                                                     'date_inserted'
          5        DO_ICALL                                             $6      
          6      > FE_RESET_R                                           $7      $6, ->31
          7    > > FE_FETCH_R                                                   $7, !2, ->31
   13     8    >   INIT_FCALL                                                   'array_filter'
          9        SEND_VAR                                                     !0
         10        DECLARE_LAMBDA_FUNCTION                              ~8      [0]
         11        BIND_LEXICAL                                                 ~8, !2
   15    12        SEND_VAL                                                     ~8
   13    13        DO_ICALL                                             $9      
   15    14      > FE_RESET_R                                           $10     $9, ->29
         15    > > FE_FETCH_R                                                   $10, !3, ->29
   16    16    >   FETCH_DIM_R                                          ~12     !3, 'marketplace'
   17    17        FETCH_DIM_R                                          ~14     !3, 'id'
         18        INIT_ARRAY                                           ~15     ~14, 'id'
   18    19        FETCH_DIM_R                                          ~16     !3, 'total_stickers'
         20        ADD_ARRAY_ELEMENT                                    ~15     ~16, 'total_stickers'
   19    21        FETCH_DIM_R                                          ~17     !3, 'total_orders'
         22        ADD_ARRAY_ELEMENT                                    ~15     ~17, 'total_orders'
   20    23        FETCH_DIM_R                                          ~18     !3, 'total_value'
         24        ADD_ARRAY_ELEMENT                                    ~15     ~18, 'total_value'
   16    25        FETCH_DIM_W                                          $11     !1, !2
         26        ASSIGN_DIM                                                   $11, ~12
   20    27        OP_DATA                                                      ~15
   13    28      > JMP                                                          ->15
         29    >   FE_FREE                                                      $10
   12    30      > JMP                                                          ->7
         31    >   FE_FREE                                                      $7
   25    32        INIT_FCALL                                                   'print_r'
         33        SEND_VAR                                                     !1
         34        DO_ICALL                                                     
         35      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QnHQf
function name:  {closure:/in/QnHQf:13}
number of ops:  6
compiled vars:  !0 = $v, !1 = $date
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   13     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
   14     2        FETCH_DIM_R                                          ~2      !0, 'date_inserted'
          3        IS_IDENTICAL                                         ~3      !1, ~2
          4      > RETURN                                                       ~3
   15     5*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
213.23 ms | 2558 KiB | 16 Q