3v4l.org

run code in 500+ PHP versions simultaneously
<?php $data = [ "date" => 1554328800, "events" => [130, 131, 163], "tags" => [4, "1,3,4", "1,3"] ]; // 1. List the events per individual tag foreach($data["tags"] as $i => $val) { $vals = explode(",", $val); foreach($vals as $val) { $eventsByTag[$val][] = $data["events"][$i]; } } // 2. List the tags per set of events foreach($eventsByTag as $tag => $events) { sort($events, SORT_NUMERIC); $tagsByEvents[implode(",", $events)][] = $tag; } // 3. produce the result foreach($tagsByEvents as $events => $tags) { $events = explode(",", $events); if (count($tags) == 1) $tags = $tags[0]; $result[] = [ "date" => $data["date"], "events" => $events, "tags" => $tags ]; } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 20
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 18
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 22, Position 2 = 33
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 33
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 35, Position 2 = 54
Branch analysis from position: 35
2 jumps found. (Code = 78) Position 1 = 36, Position 2 = 54
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 47
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
Branch analysis from position: 47
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
Branch analysis from position: 33
Branch analysis from position: 20
filename:       /in/fDsW5
function name:  (null)
number of ops:  59
compiled vars:  !0 = $data, !1 = $val, !2 = $i, !3 = $vals, !4 = $eventsByTag, !5 = $events, !6 = $tag, !7 = $tagsByEvents, !8 = $tags, !9 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   10     1        FETCH_DIM_R                                          ~11     !0, 'tags'
          2      > FE_RESET_R                                           $12     ~11, ->20
          3    > > FE_FETCH_R                                           ~13     $12, !1, ->20
          4    >   ASSIGN                                                       !2, ~13
   11     5        INIT_FCALL                                                   'explode'
          6        SEND_VAL                                                     '%2C'
          7        SEND_VAR                                                     !1
          8        DO_ICALL                                             $15     
          9        ASSIGN                                                       !3, $15
   12    10      > FE_RESET_R                                           $17     !3, ->18
         11    > > FE_FETCH_R                                                   $17, !1, ->18
   13    12    >   FETCH_DIM_R                                          ~20     !0, 'events'
         13        FETCH_DIM_R                                          ~21     ~20, !2
         14        FETCH_DIM_W                                          $18     !4, !1
         15        ASSIGN_DIM                                                   $18
         16        OP_DATA                                                      ~21
   12    17      > JMP                                                          ->11
         18    >   FE_FREE                                                      $17
   10    19      > JMP                                                          ->3
         20    >   FE_FREE                                                      $12
   18    21      > FE_RESET_R                                           $22     !4, ->33
         22    > > FE_FETCH_R                                           ~23     $22, !5, ->33
         23    >   ASSIGN                                                       !6, ~23
   19    24        INIT_FCALL                                                   'sort'
         25        SEND_REF                                                     !5
         26        SEND_VAL                                                     1
         27        DO_ICALL                                                     
   20    28        FRAMELESS_ICALL_2                implode             ~26     '%2C', !5
         29        FETCH_DIM_W                                          $27     !7, ~26
         30        ASSIGN_DIM                                                   $27
         31        OP_DATA                                                      !6
   18    32      > JMP                                                          ->22
         33    >   FE_FREE                                                      $22
   24    34      > FE_RESET_R                                           $29     !7, ->54
         35    > > FE_FETCH_R                                           ~30     $29, !8, ->54
         36    >   ASSIGN                                                       !5, ~30
   25    37        INIT_FCALL                                                   'explode'
         38        SEND_VAL                                                     '%2C'
         39        SEND_VAR                                                     !5
         40        DO_ICALL                                             $32     
         41        ASSIGN                                                       !5, $32
   26    42        COUNT                                                ~34     !8
         43        IS_EQUAL                                                     ~34, 1
         44      > JMPZ                                                         ~35, ->47
         45    >   FETCH_DIM_R                                          ~36     !8, 0
         46        ASSIGN                                                       !8, ~36
   28    47    >   FETCH_DIM_R                                          ~39     !0, 'date'
         48        INIT_ARRAY                                           ~40     ~39, 'date'
   29    49        ADD_ARRAY_ELEMENT                                    ~40     !5, 'events'
   30    50        ADD_ARRAY_ELEMENT                                    ~40     !8, 'tags'
   27    51        ASSIGN_DIM                                                   !9
   30    52        OP_DATA                                                      ~40
   24    53      > JMP                                                          ->35
         54    >   FE_FREE                                                      $29
   34    55        INIT_FCALL                                                   'print_r'
         56        SEND_VAR                                                     !9
         57        DO_ICALL                                                     
         58      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
161.75 ms | 2323 KiB | 16 Q