3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array1 = [ 1 => "tenants", 2 => "modules", ]; $array2 = [ "prefix" => "tenants", "slug" => "tenants", "child" => [ [ "prefix" => "modules/{id}", "slug" => "modules" ], [ "prefix" => "fetch/{id}", "slug" => "fetch" ], ], ]; function getFromChild($item, $asd) { if (!is_array($item)) return []; $res = []; if ($item["slug"] == $asd) $res[] = $item['prefix']; if (isset($item['child'])) foreach($item['child'] as $child) $res = array_merge($res, getFromChild($child, $asd)); return $res; } $res = []; foreach ($array1 as $asd) { $res = array_merge($res, getFromChild($array2, $asd)); } print_r($res);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 15
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/tuODQ
function name:  (null)
number of ops:  20
compiled vars:  !0 = $array1, !1 = $array2, !2 = $res, !3 = $asd
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, <array>
   36     2        ASSIGN                                                   !2, <array>
   37     3      > FE_RESET_R                                       $7      !0, ->15
          4    > > FE_FETCH_R                                               $7, !3, ->15
   38     5    >   INIT_FCALL                                               'array_merge'
          6        SEND_VAR                                                 !2
          7        INIT_FCALL                                               'getfromchild'
          8        SEND_VAR                                                 !1
          9        SEND_VAR                                                 !3
         10        DO_FCALL                                      0  $8      
         11        SEND_VAR                                                 $8
         12        DO_ICALL                                         $9      
         13        ASSIGN                                                   !2, $9
   37    14      > JMP                                                      ->4
         15    >   FE_FREE                                                  $7
   40    16        INIT_FCALL                                               'print_r'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                                 
         19      > RETURN                                                   1

Function getfromchild:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 29
Branch analysis from position: 15
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 28
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 28
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
Branch analysis from position: 29
Branch analysis from position: 13
filename:       /in/tuODQ
function name:  getFromChild
number of ops:  31
compiled vars:  !0 = $item, !1 = $asd, !2 = $res, !3 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   26     2        TYPE_CHECK                                  128  ~4      !0
          3        BOOL_NOT                                         ~5      ~4
          4      > JMPZ                                                     ~5, ->6
          5    > > RETURN                                                   <array>
   27     6    >   ASSIGN                                                   !2, <array>
   28     7        FETCH_DIM_R                                      ~7      !0, 'slug'
          8        IS_EQUAL                                                 !1, ~7
          9      > JMPZ                                                     ~8, ->13
   29    10    >   FETCH_DIM_R                                      ~10     !0, 'prefix'
         11        ASSIGN_DIM                                               !2
         12        OP_DATA                                                  ~10
   30    13    >   ISSET_ISEMPTY_DIM_OBJ                         0          !0, 'child'
         14      > JMPZ                                                     ~11, ->29
   31    15    >   FETCH_DIM_R                                      ~12     !0, 'child'
         16      > FE_RESET_R                                       $13     ~12, ->28
         17    > > FE_FETCH_R                                               $13, !3, ->28
   32    18    >   INIT_FCALL                                               'array_merge'
         19        SEND_VAR                                                 !2
         20        INIT_FCALL_BY_NAME                                       'getFromChild'
         21        SEND_VAR_EX                                              !3
         22        SEND_VAR_EX                                              !1
         23        DO_FCALL                                      0  $14     
         24        SEND_VAR                                                 $14
         25        DO_ICALL                                         $15     
         26        ASSIGN                                                   !2, $15
   31    27      > JMP                                                      ->17
         28    >   FE_FREE                                                  $13
   33    29    > > RETURN                                                   !2
   34    30*     > RETURN                                                   null

End of function getfromchild

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
123.64 ms | 1008 KiB | 16 Q