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"]; $cats = []; $ids = []; foreach ($strings as $key=>$string) { $temps = explode(';', $string); foreach ($temps as $temp) { $tempnest = explode(':', $temp); if ($tempnest[0] === "cat") { $cats = array_merge(explode(',', $tempnest[1]), $cats); } if ($tempnest[0] === "id") { $ids = array_merge(explode(',', $tempnest[1]), $ids); } } } print_r(array_unique($cats)); print_r(array_unique($ids));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 47
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 47
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 45
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 45
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 31
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 44
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 44
Branch analysis from position: 31
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 45
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
filename:       /in/sSDj4
function name:  (null)
number of ops:  61
compiled vars:  !0 = $strings, !1 = $cats, !2 = $ids, !3 = $string, !4 = $key, !5 = $temps, !6 = $temp, !7 = $tempnest
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, <array>
    6     3      > FE_RESET_R                                       $11     !0, ->47
          4    > > FE_FETCH_R                                       ~12     $11, !3, ->47
          5    >   ASSIGN                                                   !4, ~12
    7     6        INIT_FCALL                                               'explode'
          7        SEND_VAL                                                 '%3B'
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $14     
         10        ASSIGN                                                   !5, $14
    9    11      > FE_RESET_R                                       $16     !5, ->45
         12    > > FE_FETCH_R                                               $16, !6, ->45
   10    13    >   INIT_FCALL                                               'explode'
         14        SEND_VAL                                                 '%3A'
         15        SEND_VAR                                                 !6
         16        DO_ICALL                                         $17     
         17        ASSIGN                                                   !7, $17
   12    18        FETCH_DIM_R                                      ~19     !7, 0
         19        IS_IDENTICAL                                             ~19, 'cat'
         20      > JMPZ                                                     ~20, ->31
   13    21    >   INIT_FCALL                                               'array_merge'
         22        INIT_FCALL                                               'explode'
         23        SEND_VAL                                                 '%2C'
         24        FETCH_DIM_R                                      ~21     !7, 1
         25        SEND_VAL                                                 ~21
         26        DO_ICALL                                         $22     
         27        SEND_VAR                                                 $22
         28        SEND_VAR                                                 !1
         29        DO_ICALL                                         $23     
         30        ASSIGN                                                   !1, $23
   15    31    >   FETCH_DIM_R                                      ~25     !7, 0
         32        IS_IDENTICAL                                             ~25, 'id'
         33      > JMPZ                                                     ~26, ->44
   16    34    >   INIT_FCALL                                               'array_merge'
         35        INIT_FCALL                                               'explode'
         36        SEND_VAL                                                 '%2C'
         37        FETCH_DIM_R                                      ~27     !7, 1
         38        SEND_VAL                                                 ~27
         39        DO_ICALL                                         $28     
         40        SEND_VAR                                                 $28
         41        SEND_VAR                                                 !2
         42        DO_ICALL                                         $29     
         43        ASSIGN                                                   !2, $29
    9    44    > > JMP                                                      ->12
         45    >   FE_FREE                                                  $16
    6    46      > JMP                                                      ->4
         47    >   FE_FREE                                                  $11
   21    48        INIT_FCALL                                               'print_r'
         49        INIT_FCALL                                               'array_unique'
         50        SEND_VAR                                                 !1
         51        DO_ICALL                                         $31     
         52        SEND_VAR                                                 $31
         53        DO_ICALL                                                 
   22    54        INIT_FCALL                                               'print_r'
         55        INIT_FCALL                                               'array_unique'
         56        SEND_VAR                                                 !2
         57        DO_ICALL                                         $33     
         58        SEND_VAR                                                 $33
         59        DO_ICALL                                                 
         60      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.53 ms | 1013 KiB | 17 Q