3v4l.org

run code in 300+ PHP versions simultaneously
<?php $structure = [ "1" => [ 'id' => '1', 'username' => 'username', 'children' => [ [ 'id' => '-1', 'username' => 'NULL', 'children' => [ [ 'id' => '-1', 'username' => 'NULL', 'children' => [ [ 'id' => '-1', 'username' => 'NULL', 'children' => [], ], ], ], ], ], ], ], ]; $entry = [ 157 => [ 'id' => '157', 'username' => 'test1', 'children' => [ [ 'id' => '158', 'username' => 'test1', 'children' => [ [ 'id' => '159', 'username' => 'test2', 'children' => [ [ 'id' => '160', 'username' => 'test3', 'children' => [], ], [ 'id' => '160', 'username' => 'KICK ME BECAUSE I M NOT EXIST IN FIRST ARRAY', 'children' => [], ], ], ], ], ], [ 'id' => '160', 'username' => 'KICK ME BECAUSE I M NOT EXIST IN FIRST ARRAY', 'children' => [ [ 'id' => '159', 'username' => 'KICK ME BECAUSE I M NOT EXIST IN FIRST ARRAY', 'children' => [ [ 'id' => '161', 'username' => 'KICK ME BECAUSE I M NOT EXIST IN FIRST ARRAY', 'children' => [], ], ], ], ], ], ], ], ]; function truncateRecursive($structure, $entry) { $output = []; while (($structureKey = key($structure)) !== null && ($entryKey = key($entry)) !== null) { $output[$entryKey] = !is_array($entry[$entryKey]) ? $entry[$entryKey] : truncateRecursive($structure[$structureKey], $entry[$entryKey]); unset($structure[$structureKey], $entry[$entryKey]); } return $output; } var_export(truncateRecursive($structure, $entry));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gbs9Y
function name:  (null)
number of ops:  10
compiled vars:  !0 = $structure, !1 = $entry
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   28     1        ASSIGN                                                   !1, <array>
   87     2        INIT_FCALL                                               'var_export'
          3        INIT_FCALL                                               'truncaterecursive'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function truncaterecursive:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 46) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 4
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 46) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
Branch analysis from position: 36
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
Branch analysis from position: 36
Branch analysis from position: 36
filename:       /in/gbs9Y
function name:  truncateRecursive
number of ops:  39
compiled vars:  !0 = $structure, !1 = $entry, !2 = $output, !3 = $entryKey, !4 = $structureKey
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   77     2        ASSIGN                                                   !2, <array>
   78     3      > JMP                                                      ->24
   79     4    >   FETCH_DIM_R                                      ~7      !1, !3
          5        TYPE_CHECK                                  128  ~8      ~7
          6        BOOL_NOT                                         ~9      ~8
          7      > JMPZ                                                     ~9, ->11
   80     8    >   FETCH_DIM_R                                      ~10     !1, !3
          9        QM_ASSIGN                                        ~11     ~10
         10      > JMP                                                      ->20
   81    11    >   INIT_FCALL_BY_NAME                                       'truncateRecursive'
         12        CHECK_FUNC_ARG                                           
         13        FETCH_DIM_FUNC_ARG                               $12     !0, !4
         14        SEND_FUNC_ARG                                            $12
         15        CHECK_FUNC_ARG                                           
         16        FETCH_DIM_FUNC_ARG                               $13     !1, !3
         17        SEND_FUNC_ARG                                            $13
         18        DO_FCALL                                      0  $14     
         19        QM_ASSIGN                                        ~11     $14
   79    20    >   ASSIGN_DIM                                               !2, !3
   81    21        OP_DATA                                                  ~11
   82    22        UNSET_DIM                                                !0, !4
         23        UNSET_DIM                                                !1, !3
   78    24    >   INIT_FCALL                                               'key'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $15     
         27        ASSIGN                                           ~16     !4, $15
         28        TYPE_CHECK                                  1020  ~17     ~16
         29      > JMPZ_EX                                          ~17     ~17, ->36
         30    >   INIT_FCALL                                               'key'
         31        SEND_VAR                                                 !1
         32        DO_ICALL                                         $18     
         33        ASSIGN                                           ~19     !3, $18
         34        TYPE_CHECK                                  1020  ~20     ~19
         35        BOOL                                             ~17     ~20
         36    > > JMPNZ                                                    ~17, ->4
   84    37    > > RETURN                                                   !2
   85    38*     > RETURN                                                   null

End of function truncaterecursive

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.54 ms | 961 KiB | 16 Q