3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* 1 2 3 4 5 - 6 - 7 */ $a = ['d'=>1, 'l'=>&$b, 'r'=>&$c]; $b = ['d'=>2, 'l'=>&$d, 'r'=>&$e]; $c = ['d'=>3, 'l'=>null, 'r'=>&$f]; $d = ['d'=>4, 'l'=>null, 'r'=>&$g]; $e = ['d'=>5, 'l'=>null, 'r'=>null]; $f = ['d'=>6, 'l'=>null, 'r'=>null]; $g = ['d'=>7, 'l'=>null, 'r'=>null]; bfs($a); echo "\n"; dfs($a); function bfs($t) { $queue = [$t]; while ($queue) { $node = array_shift($queue); echo $node['d']; if (is_array($node['l'])) { array_push($queue, $node['l']); } if (is_array($node['r'])) { array_push($queue, $node['r']); } } } function dfs($t) { $stack = [$t]; while ($stack) { $node = array_pop($stack); echo $node['d']; if (is_array($node['r'])) { array_push($stack, $node['r']); } if (is_array($node['l'])) { array_push($stack, $node['l']); } } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0GIsm
function name:  (null)
number of ops:  27
compiled vars:  !0 = $a, !1 = $b, !2 = $c, !3 = $d, !4 = $e, !5 = $f, !6 = $g
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   INIT_ARRAY                                       ~7      1, 'd'
          1        ADD_ARRAY_ELEMENT                                ~7      !1, 'l'
          2        ADD_ARRAY_ELEMENT                                ~7      !2, 'r'
          3        ASSIGN                                                   !0, ~7
    9     4        INIT_ARRAY                                       ~9      2, 'd'
          5        ADD_ARRAY_ELEMENT                                ~9      !3, 'l'
          6        ADD_ARRAY_ELEMENT                                ~9      !4, 'r'
          7        ASSIGN                                                   !1, ~9
   10     8        INIT_ARRAY                                       ~11     3, 'd'
          9        ADD_ARRAY_ELEMENT                                ~11     null, 'l'
         10        ADD_ARRAY_ELEMENT                                ~11     !5, 'r'
         11        ASSIGN                                                   !2, ~11
   11    12        INIT_ARRAY                                       ~13     4, 'd'
         13        ADD_ARRAY_ELEMENT                                ~13     null, 'l'
         14        ADD_ARRAY_ELEMENT                                ~13     !6, 'r'
         15        ASSIGN                                                   !3, ~13
   12    16        ASSIGN                                                   !4, <array>
   13    17        ASSIGN                                                   !5, <array>
   14    18        ASSIGN                                                   !6, <array>
   16    19        INIT_FCALL_BY_NAME                                       'bfs'
         20        SEND_VAR_EX                                              !0
         21        DO_FCALL                                      0          
   17    22        ECHO                                                     '%0A'
   18    23        INIT_FCALL_BY_NAME                                       'dfs'
         24        SEND_VAR_EX                                              !0
         25        DO_FCALL                                      0          
   46    26      > RETURN                                                   1

Function bfs:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 4
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 4
Branch analysis from position: 27
Branch analysis from position: 4
Branch analysis from position: 26
Branch analysis from position: 18
filename:       /in/0GIsm
function name:  bfs
number of ops:  28
compiled vars:  !0 = $t, !1 = $queue, !2 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        INIT_ARRAY                                       ~3      !0
          2        ASSIGN                                                   !1, ~3
   22     3      > JMP                                                      ->26
   23     4    >   INIT_FCALL                                               'array_shift'
          5        SEND_REF                                                 !1
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !2, $5
   24     8        FETCH_DIM_R                                      ~7      !2, 'd'
          9        ECHO                                                     ~7
   25    10        FETCH_DIM_R                                      ~8      !2, 'l'
         11        TYPE_CHECK                                  128          ~8
         12      > JMPZ                                                     ~9, ->18
   26    13    >   INIT_FCALL                                               'array_push'
         14        SEND_REF                                                 !1
         15        FETCH_DIM_R                                      ~10     !2, 'l'
         16        SEND_VAL                                                 ~10
         17        DO_ICALL                                                 
   28    18    >   FETCH_DIM_R                                      ~12     !2, 'r'
         19        TYPE_CHECK                                  128          ~12
         20      > JMPZ                                                     ~13, ->26
   29    21    >   INIT_FCALL                                               'array_push'
         22        SEND_REF                                                 !1
         23        FETCH_DIM_R                                      ~14     !2, 'r'
         24        SEND_VAL                                                 ~14
         25        DO_ICALL                                                 
   22    26    > > JMPNZ                                                    !1, ->4
   32    27    > > RETURN                                                   null

End of function bfs

Function dfs:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 4
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 26
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 4
Branch analysis from position: 27
Branch analysis from position: 4
Branch analysis from position: 26
Branch analysis from position: 18
filename:       /in/0GIsm
function name:  dfs
number of ops:  28
compiled vars:  !0 = $t, !1 = $stack, !2 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   35     1        INIT_ARRAY                                       ~3      !0
          2        ASSIGN                                                   !1, ~3
   36     3      > JMP                                                      ->26
   37     4    >   INIT_FCALL                                               'array_pop'
          5        SEND_REF                                                 !1
          6        DO_ICALL                                         $5      
          7        ASSIGN                                                   !2, $5
   38     8        FETCH_DIM_R                                      ~7      !2, 'd'
          9        ECHO                                                     ~7
   39    10        FETCH_DIM_R                                      ~8      !2, 'r'
         11        TYPE_CHECK                                  128          ~8
         12      > JMPZ                                                     ~9, ->18
   40    13    >   INIT_FCALL                                               'array_push'
         14        SEND_REF                                                 !1
         15        FETCH_DIM_R                                      ~10     !2, 'r'
         16        SEND_VAL                                                 ~10
         17        DO_ICALL                                                 
   42    18    >   FETCH_DIM_R                                      ~12     !2, 'l'
         19        TYPE_CHECK                                  128          ~12
         20      > JMPZ                                                     ~13, ->26
   43    21    >   INIT_FCALL                                               'array_push'
         22        SEND_REF                                                 !1
         23        FETCH_DIM_R                                      ~14     !2, 'l'
         24        SEND_VAL                                                 ~14
         25        DO_ICALL                                                 
   36    26    > > JMPNZ                                                    !1, ->4
   46    27    > > RETURN                                                   null

End of function dfs

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.63 ms | 1404 KiB | 19 Q