3v4l.org

run code in 300+ PHP versions simultaneously
<?php $j = <<<EOD [{"id": 1, "product": {"id": 1, "brand": {"id": 1, "name": "iphone"}}, "provider": {"id": 1, "name": "at&t"}}, {"id": 2, "product": {"id": 2, "brand": {"id": 2, "name": "iphone"}}, "provider": {"id": 1, "name": "at&t"}}, {"id": 3, "product": {"id": 3, "brand": {"id": 3, "name": "iphone"}}, "provider": {"id": 1, "name": "t-mobile"}}] EOD; $items = json_decode($j); $tm = array(); foreach ($items as $item) { $product = $item->product->brand->name; $provider = $item->provider->name; $tm[$provider][$product] = ($tm[$provider][$product] ?? 0) + 1; } print_r($tm);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 24
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 24
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/tDnZW
function name:  (null)
number of ops:  29
compiled vars:  !0 = $j, !1 = $items, !2 = $tm, !3 = $item, !4 = $product, !5 = $provider
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%7B%22id%22%3A+1%2C+%22product%22%3A+%7B%22id%22%3A+1%2C+%22brand%22%3A+%7B%22id%22%3A+1%2C+%22name%22%3A+%22iphone%22%7D%7D%2C+%22provider%22%3A+%7B%22id%22%3A+1%2C+%22name%22%3A+%22at%26t%22%7D%7D%2C+%7B%22id%22%3A+2%2C+%22product%22%3A+%7B%22id%22%3A+2%2C+%22brand%22%3A+%7B%22id%22%3A+2%2C+%22name%22%3A+%22iphone%22%7D%7D%2C+%22provider%22%3A+%7B%22id%22%3A+1%2C+%22name%22%3A+%22at%26t%22%7D%7D%2C+%7B%22id%22%3A+3%2C+%22product%22%3A+%7B%22id%22%3A+3%2C+%22brand%22%3A+%7B%22id%22%3A+3%2C+%22name%22%3A+%22iphone%22%7D%7D%2C+%22provider%22%3A+%7B%22id%22%3A+1%2C+%22name%22%3A+%22t-mobile%22%7D%7D%5D'
    6     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $7      
          4        ASSIGN                                                   !1, $7
    8     5        ASSIGN                                                   !2, <array>
    9     6      > FE_RESET_R                                       $10     !1, ->24
          7    > > FE_FETCH_R                                               $10, !3, ->24
   10     8    >   FETCH_OBJ_R                                      ~11     !3, 'product'
          9        FETCH_OBJ_R                                      ~12     ~11, 'brand'
         10        FETCH_OBJ_R                                      ~13     ~12, 'name'
         11        ASSIGN                                                   !4, ~13
   11    12        FETCH_OBJ_R                                      ~15     !3, 'provider'
         13        FETCH_OBJ_R                                      ~16     ~15, 'name'
         14        ASSIGN                                                   !5, ~16
   12    15        FETCH_DIM_IS                                     ~20     !2, !5
         16        FETCH_DIM_IS                                     ~21     ~20, !4
         17        COALESCE                                         ~22     ~21
         18        QM_ASSIGN                                        ~22     0
         19        ADD                                              ~23     ~22, 1
         20        FETCH_DIM_W                                      $18     !2, !5
         21        ASSIGN_DIM                                               $18, !4
         22        OP_DATA                                                  ~23
    9    23      > JMP                                                      ->7
         24    >   FE_FREE                                                  $10
   15    25        INIT_FCALL                                               'print_r'
         26        SEND_VAR                                                 !2
         27        DO_ICALL                                                 
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.78 ms | 1007 KiB | 15 Q