3v4l.org

run code in 300+ PHP versions simultaneously
<?php $strings = [ "cat:others;id:4,9,13", "id:4,9,13;cat:electric-products", "id:4,9,13;cat:foods", "cat:drinks,foods" ]; $result = ['id' => [], 'cat' => []]; foreach ($strings as $string) { foreach (explode(';', $string) as $segment) { [$key, $values] = explode(':', $segment, 2); array_push($result[$key], ...explode(',', $values)); } } var_export(array_unique($result['id'])); echo "\n---\n"; var_export(array_unique($result['cat']));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 33
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 33
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 31
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 31
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 31
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/6vRYe
function name:  (null)
number of ops:  50
compiled vars:  !0 = $strings, !1 = $result, !2 = $string, !3 = $segment, !4 = $key, !5 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   10     1        ASSIGN                                                   !1, <array>
   11     2      > FE_RESET_R                                       $8      !0, ->33
          3    > > FE_FETCH_R                                               $8, !2, ->33
   12     4    >   INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '%3B'
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $9      
          8      > FE_RESET_R                                       $10     $9, ->31
          9    > > FE_FETCH_R                                               $10, !3, ->31
   13    10    >   INIT_FCALL                                               'explode'
         11        SEND_VAL                                                 '%3A'
         12        SEND_VAR                                                 !3
         13        SEND_VAL                                                 2
         14        DO_ICALL                                         $11     
         15        FETCH_LIST_R                                     $12     $11, 0
         16        ASSIGN                                                   !4, $12
         17        FETCH_LIST_R                                     $14     $11, 1
         18        ASSIGN                                                   !5, $14
         19        FREE                                                     $11
   14    20        INIT_FCALL                                               'array_push'
         21        FETCH_DIM_W                                      $16     !1, !4
         22        SEND_REF                                                 $16
         23        INIT_FCALL                                               'explode'
         24        SEND_VAL                                                 '%2C'
         25        SEND_VAR                                                 !5
         26        DO_ICALL                                         $17     
         27        SEND_UNPACK                                              $17
         28        CHECK_UNDEF_ARGS                                         
         29        DO_ICALL                                                 
   12    30      > JMP                                                      ->9
         31    >   FE_FREE                                                  $10
   11    32      > JMP                                                      ->3
         33    >   FE_FREE                                                  $8
   18    34        INIT_FCALL                                               'var_export'
         35        INIT_FCALL                                               'array_unique'
         36        FETCH_DIM_R                                      ~19     !1, 'id'
         37        SEND_VAL                                                 ~19
         38        DO_ICALL                                         $20     
         39        SEND_VAR                                                 $20
         40        DO_ICALL                                                 
   19    41        ECHO                                                     '%0A---%0A'
   20    42        INIT_FCALL                                               'var_export'
         43        INIT_FCALL                                               'array_unique'
         44        FETCH_DIM_R                                      ~22     !1, 'cat'
         45        SEND_VAL                                                 ~22
         46        DO_ICALL                                         $23     
         47        SEND_VAR                                                 $23
         48        DO_ICALL                                                 
         49      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.43 ms | 1018 KiB | 17 Q