3v4l.org

run code in 300+ PHP versions simultaneously
<?php function print_while_each($list) { while (list($key, $val) = each($list)) { echo $key, $val; if ($val == '2') { $list[] = 4; } } } function print_foreach($list) { foreach ($list as $key => $val) { echo $key, $val; if ($val == '2') { $list[] = 4; } } } function print_while_next($list) { $val = reset($list); while (!empty($val)) { $key = key($list); $val = current($list); echo $key, $val; if ($val == '2') { $list[] = 4; } $val = next($list); } } $list = array('1', '2', '3'); print_while_each($list); echo '<br>', PHP_EOL; print_foreach($list); echo '<br>', PHP_EOL; print_while_next($list); echo '<br>', PHP_EOL;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/g77Ae
function name:  (null)
number of ops:  17
compiled vars:  !0 = $list
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   ASSIGN                                                   !0, <array>
   37     1        INIT_FCALL                                               'print_while_each'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0          
   38     4        ECHO                                                     '%3Cbr%3E'
          5        ECHO                                                     '%0A'
   40     6        INIT_FCALL                                               'print_foreach'
          7        SEND_VAR                                                 !0
          8        DO_FCALL                                      0          
   41     9        ECHO                                                     '%3Cbr%3E'
         10        ECHO                                                     '%0A'
   43    11        INIT_FCALL                                               'print_while_next'
         12        SEND_VAR                                                 !0
         13        DO_FCALL                                      0          
   44    14        ECHO                                                     '%3Cbr%3E'
         15        ECHO                                                     '%0A'
         16      > RETURN                                                   1

Function print_while_each:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 2
Branch analysis from position: 16
Branch analysis from position: 2
Branch analysis from position: 8
filename:       /in/g77Ae
function name:  print_while_each
number of ops:  17
compiled vars:  !0 = $list, !1 = $key, !2 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1      > JMP                                                      ->8
    5     2    >   ECHO                                                     !1
          3        ECHO                                                     !2
    6     4        IS_EQUAL                                                 !2, '2'
          5      > JMPZ                                                     ~3, ->8
    7     6    >   ASSIGN_DIM                                               !0
          7        OP_DATA                                                  4
    4     8    >   INIT_FCALL_BY_NAME                                       'each'
          9        SEND_VAR_EX                                              !0
         10        DO_FCALL                                      0  $5      
         11        FETCH_LIST_R                                     $6      $5, 0
         12        ASSIGN                                                   !1, $6
         13        FETCH_LIST_R                                     $8      $5, 1
         14        ASSIGN                                                   !2, $8
         15      > JMPNZ                                                    $5, ->2
   10    16    > > RETURN                                                   null

End of function print_while_each

Function print_foreach:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 11
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 11
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 10
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/g77Ae
function name:  print_foreach
number of ops:  13
compiled vars:  !0 = $list, !1 = $val, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
   13     1      > FE_RESET_R                                       $3      !0, ->11
          2    > > FE_FETCH_R                                       ~4      $3, !1, ->11
          3    >   ASSIGN                                                   !2, ~4
   14     4        ECHO                                                     !2
          5        ECHO                                                     !1
   15     6        IS_EQUAL                                                 !1, '2'
          7      > JMPZ                                                     ~6, ->10
   16     8    >   ASSIGN_DIM                                               !0
          9        OP_DATA                                                  4
   13    10    > > JMP                                                      ->2
         11    >   FE_FREE                                                  $3
   19    12      > RETURN                                                   null

End of function print_foreach

Function print_while_next:
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 = 44) Position 1 = 27, Position 2 = 6
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 6
Branch analysis from position: 27
Branch analysis from position: 6
Branch analysis from position: 20
filename:       /in/g77Ae
function name:  print_while_next
number of ops:  28
compiled vars:  !0 = $list, !1 = $val, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        INIT_FCALL                                               'reset'
          2        SEND_REF                                                 !0
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !1, $3
   23     5      > JMP                                                      ->24
   24     6    >   INIT_FCALL                                               'key'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !2, $5
   25    10        INIT_FCALL                                               'current'
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $7      
         13        ASSIGN                                                   !1, $7
   27    14        ECHO                                                     !2
         15        ECHO                                                     !1
   28    16        IS_EQUAL                                                 !1, '2'
         17      > JMPZ                                                     ~9, ->20
   29    18    >   ASSIGN_DIM                                               !0
         19        OP_DATA                                                  4
   31    20    >   INIT_FCALL                                               'next'
         21        SEND_REF                                                 !0
         22        DO_ICALL                                         $11     
         23        ASSIGN                                                   !1, $11
   23    24    >   ISSET_ISEMPTY_CV                                 ~13     !1
         25        BOOL_NOT                                         ~14     ~13
         26      > JMPNZ                                                    ~14, ->6
   33    27    > > RETURN                                                   null

End of function print_while_next

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.65 ms | 1014 KiB | 20 Q