3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = [ [ '1@02@43@170@1', '1@02@43@176@1', '1@02@43@182@1', '1@02@42@182@1', '1@02@42@176@1', ], [ '1@02@43@170@1', '1@02@43@176@1', '1@02@43@182@1', '1@02@42@182@1', '1@02@42@176@1', '1@03@43@170@1', '1@03@43@176@1', '1@03@43@182@1', '1@03@42@182@1', '1@03@42@176@1', ], [ '1@02@43@170@1', '1@02@43@170@1', ] ]; function killYourParentIfYouHaveOne($level) { if (count($level) === 1) { $key = key($level); $level = is_array($level[$key]) ? killYourParentIfYouHaveOne($level[$key]) : []; } return $level; } function differingTree(array $array): array { $result = []; foreach ($array as $item) { [$a, $b, $c, $d, $e] = explode('@', $item, 5); $result[$a][$b][$c][$d] = $e; } return killYourParentIfYouHaveOne($result); } foreach ($tests as $test) { echo var_export(differingTree($test), true) . "\n---\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 13
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/H0IhR
function name:  (null)
number of ops:  15
compiled vars:  !0 = $tests, !1 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   46     1      > FE_RESET_R                                       $3      !0, ->13
          2    > > FE_FETCH_R                                               $3, !1, ->13
   47     3    >   INIT_FCALL                                               'var_export'
          4        INIT_FCALL                                               'differingtree'
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        SEND_VAL                                                 <true>
          9        DO_ICALL                                         $5      
         10        CONCAT                                           ~6      $5, '%0A---%0A'
         11        ECHO                                                     ~6
   46    12      > JMP                                                      ->2
         13    >   FE_FREE                                                  $3
   48    14      > RETURN                                                   1

Function killyourparentifyouhaveone:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 20
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 18
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/H0IhR
function name:  killYourParentIfYouHaveOne
number of ops:  22
compiled vars:  !0 = $level, !1 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        COUNT                                            ~2      !0
          2        IS_IDENTICAL                                             ~2, 1
          3      > JMPZ                                                     ~3, ->20
   31     4    >   INIT_FCALL                                               'key'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $4      
          7        ASSIGN                                                   !1, $4
   32     8        FETCH_DIM_R                                      ~6      !0, !1
          9        TYPE_CHECK                                  128          ~6
         10      > JMPZ                                                     ~7, ->18
         11    >   INIT_FCALL_BY_NAME                                       'killYourParentIfYouHaveOne'
         12        CHECK_FUNC_ARG                                           
         13        FETCH_DIM_FUNC_ARG                               $8      !0, !1
         14        SEND_FUNC_ARG                                            $8
         15        DO_FCALL                                      0  $9      
         16        QM_ASSIGN                                        ~10     $9
         17      > JMP                                                      ->19
         18    >   QM_ASSIGN                                        ~10     <array>
         19    >   ASSIGN                                                   !0, ~10
   34    20    > > RETURN                                                   !0
   35    21*     > RETURN                                                   null

End of function killyourparentifyouhaveone

Function differingtree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 26
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 26
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/H0IhR
function name:  differingTree
number of ops:  34
compiled vars:  !0 = $array, !1 = $result, !2 = $item, !3 = $a, !4 = $b, !5 = $c, !6 = $d, !7 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   RECV                                             !0      
   38     1        ASSIGN                                                   !1, <array>
   39     2      > FE_RESET_R                                       $9      !0, ->26
          3    > > FE_FETCH_R                                               $9, !2, ->26
   40     4    >   INIT_FCALL                                               'explode'
          5        SEND_VAL                                                 '%40'
          6        SEND_VAR                                                 !2
          7        SEND_VAL                                                 5
          8        DO_ICALL                                         $10     
          9        FETCH_LIST_R                                     $11     $10, 0
         10        ASSIGN                                                   !3, $11
         11        FETCH_LIST_R                                     $13     $10, 1
         12        ASSIGN                                                   !4, $13
         13        FETCH_LIST_R                                     $15     $10, 2
         14        ASSIGN                                                   !5, $15
         15        FETCH_LIST_R                                     $17     $10, 3
         16        ASSIGN                                                   !6, $17
         17        FETCH_LIST_R                                     $19     $10, 4
         18        ASSIGN                                                   !7, $19
         19        FREE                                                     $10
   41    20        FETCH_DIM_W                                      $21     !1, !3
         21        FETCH_DIM_W                                      $22     $21, !4
         22        FETCH_DIM_W                                      $23     $22, !5
         23        ASSIGN_DIM                                               $23, !6
         24        OP_DATA                                                  !7
   39    25      > JMP                                                      ->3
         26    >   FE_FREE                                                  $9
   43    27        INIT_FCALL                                               'killyourparentifyouhaveone'
         28        SEND_VAR                                                 !1
         29        DO_FCALL                                      0  $25     
         30        VERIFY_RETURN_TYPE                                       $25
         31      > RETURN                                                   $25
   44    32*       VERIFY_RETURN_TYPE                                       
         33*     > RETURN                                                   null

End of function differingtree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.15 ms | 1024 KiB | 18 Q