3v4l.org

run code in 300+ 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 = 36
Branch analysis from position: 22
2 jumps found. (Code = 78) Position 1 = 23, Position 2 = 36
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 36
2 jumps found. (Code = 77) Position 1 = 38, Position 2 = 57
Branch analysis from position: 38
2 jumps found. (Code = 78) Position 1 = 39, Position 2 = 57
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 50
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 50
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
Branch analysis from position: 36
Branch analysis from position: 20
filename:       /in/fDsW5
function name:  (null)
number of ops:  62
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, ->36
         22    > > FE_FETCH_R                                       ~23     $22, !5, ->36
         23    >   ASSIGN                                                   !6, ~23
   19    24        INIT_FCALL                                               'sort'
         25        SEND_REF                                                 !5
         26        SEND_VAL                                                 1
         27        DO_ICALL                                                 
   20    28        INIT_FCALL                                               'implode'
         29        SEND_VAL                                                 '%2C'
         30        SEND_VAR                                                 !5
         31        DO_ICALL                                         $26     
         32        FETCH_DIM_W                                      $27     !7, $26
         33        ASSIGN_DIM                                               $27
         34        OP_DATA                                                  !6
   18    35      > JMP                                                      ->22
         36    >   FE_FREE                                                  $22
   24    37      > FE_RESET_R                                       $29     !7, ->57
         38    > > FE_FETCH_R                                       ~30     $29, !8, ->57
         39    >   ASSIGN                                                   !5, ~30
   25    40        INIT_FCALL                                               'explode'
         41        SEND_VAL                                                 '%2C'
         42        SEND_VAR                                                 !5
         43        DO_ICALL                                         $32     
         44        ASSIGN                                                   !5, $32
   26    45        COUNT                                            ~34     !8
         46        IS_EQUAL                                                 ~34, 1
         47      > JMPZ                                                     ~35, ->50
         48    >   FETCH_DIM_R                                      ~36     !8, 0
         49        ASSIGN                                                   !8, ~36
   28    50    >   FETCH_DIM_R                                      ~39     !0, 'date'
         51        INIT_ARRAY                                       ~40     ~39, 'date'
   29    52        ADD_ARRAY_ELEMENT                                ~40     !5, 'events'
   30    53        ADD_ARRAY_ELEMENT                                ~40     !8, 'tags'
   27    54        ASSIGN_DIM                                               !9
   30    55        OP_DATA                                                  ~40
   24    56      > JMP                                                      ->38
         57    >   FE_FREE                                                  $29
   34    58        INIT_FCALL                                               'print_r'
         59        SEND_VAR                                                 !9
         60        DO_ICALL                                                 
         61      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
271.17 ms | 1013 KiB | 17 Q