3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Test results $array1 = test('array_walk'); $array2 = test('array_walk_list_each'); $array3 = test('array_walk_foreach1'); $array4 = test('array_walk_foreach2'); // Check arrays for equal var_dump($array1 == $array2, $array1 == $array3, $array1 == $array4); // Test function 1 function array_walk_list_each(&$array, $function, $userData = null) { while ( list($key, $value) = each($array) ) $function($array[$key], $key, $userData); } // Test function 2 function array_walk_foreach1(&$array, $function, $userData = null) { foreach ($array as $key => &$value ) $function($value, $key, $userData); } // Test function 3 function array_walk_foreach2(&$array, $function, $userData = null) { foreach ($array as $key => $value ) $function($array[$key], $key, $userData); } function some_function(&$value, $key, $userData) { $value = "$key => $userData"; } function test($function, $count = 10000, $arrayElements = 1000) { echo $function, ' ... '; $array = array_fill(0, $arrayElements, "some text value"); $timer = microtime(true); for( $i = 0; ++$i < $count; ) $function($array, 'some_function', 'some user data'); printf("%.3f sec\n", microtime(true) - $timer); return $array; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F5oG9
function name:  (null)
number of ops:  25
compiled vars:  !0 = $array1, !1 = $array2, !2 = $array3, !3 = $array4
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL_BY_NAME                                       'test'
          1        SEND_VAL_EX                                              'array_walk'
          2        DO_FCALL                                      0  $4      
          3        ASSIGN                                                   !0, $4
    4     4        INIT_FCALL_BY_NAME                                       'test'
          5        SEND_VAL_EX                                              'array_walk_list_each'
          6        DO_FCALL                                      0  $6      
          7        ASSIGN                                                   !1, $6
    5     8        INIT_FCALL_BY_NAME                                       'test'
          9        SEND_VAL_EX                                              'array_walk_foreach1'
         10        DO_FCALL                                      0  $8      
         11        ASSIGN                                                   !2, $8
    6    12        INIT_FCALL_BY_NAME                                       'test'
         13        SEND_VAL_EX                                              'array_walk_foreach2'
         14        DO_FCALL                                      0  $10     
         15        ASSIGN                                                   !3, $10
   10    16        INIT_FCALL                                               'var_dump'
         17        IS_EQUAL                                         ~12     !0, !1
         18        SEND_VAL                                                 ~12
         19        IS_EQUAL                                         ~13     !0, !2
         20        SEND_VAL                                                 ~13
         21        IS_EQUAL                                         ~14     !0, !3
         22        SEND_VAL                                                 ~14
         23        DO_ICALL                                                 
   42    24      > RETURN                                                   1

Function array_walk_list_each:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 4
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 4
Branch analysis from position: 19
Branch analysis from position: 4
filename:       /in/F5oG9
function name:  array_walk_list_each
number of ops:  20
compiled vars:  !0 = $array, !1 = $function, !2 = $userData, !3 = $key, !4 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   14     3      > JMP                                                      ->11
   15     4    >   INIT_DYNAMIC_CALL                                        !1
          5        CHECK_FUNC_ARG                                           
          6        FETCH_DIM_FUNC_ARG                               $5      !0, !3
          7        SEND_FUNC_ARG                                            $5
          8        SEND_VAR_EX                                              !3
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0          
   14    11    >   INIT_FCALL_BY_NAME                                       'each'
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0  $7      
         14        FETCH_LIST_R                                     $8      $7, 0
         15        ASSIGN                                                   !3, $8
         16        FETCH_LIST_R                                     $10     $7, 1
         17        ASSIGN                                                   !4, $10
         18      > JMPNZ                                                    $7, ->4
   16    19    > > RETURN                                                   null

End of function array_walk_list_each

Function array_walk_foreach1:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 126) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/F5oG9
function name:  array_walk_foreach1
number of ops:  14
compiled vars:  !0 = $array, !1 = $function, !2 = $userData, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   20     3      > FE_RESET_RW                                      $5      !0, ->12
          4    > > FE_FETCH_RW                                      ~6      $5, !3, ->12
          5    >   ASSIGN                                                   !4, ~6
   21     6        INIT_DYNAMIC_CALL                                        !1
          7        SEND_VAR_EX                                              !3
          8        SEND_VAR_EX                                              !4
          9        SEND_VAR_EX                                              !2
         10        DO_FCALL                                      0          
   20    11      > JMP                                                      ->4
         12    >   FE_FREE                                                  $5
   22    13      > RETURN                                                   null

End of function array_walk_foreach1

Function array_walk_foreach2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 14
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 14
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/F5oG9
function name:  array_walk_foreach2
number of ops:  16
compiled vars:  !0 = $array, !1 = $function, !2 = $userData, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      null
   26     3      > FE_RESET_R                                       $5      !0, ->14
          4    > > FE_FETCH_R                                       ~6      $5, !3, ->14
          5    >   ASSIGN                                                   !4, ~6
   27     6        INIT_DYNAMIC_CALL                                        !1
          7        CHECK_FUNC_ARG                                           
          8        FETCH_DIM_FUNC_ARG                               $8      !0, !4
          9        SEND_FUNC_ARG                                            $8
         10        SEND_VAR_EX                                              !4
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0          
   26    13      > JMP                                                      ->4
         14    >   FE_FREE                                                  $5
   28    15      > RETURN                                                   null

End of function array_walk_foreach2

Function some_function:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/F5oG9
function name:  some_function
number of ops:  8
compiled vars:  !0 = $value, !1 = $key, !2 = $userData
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   31     3        ROPE_INIT                                     3  ~4      !1
          4        ROPE_ADD                                      1  ~4      ~4, '+%3D%3E+'
          5        ROPE_END                                      2  ~3      ~4, !2
          6        ASSIGN                                                   !0, ~3
   32     7      > RETURN                                                   null

End of function some_function

Function test:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 17
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 17
Branch analysis from position: 25
Branch analysis from position: 17
filename:       /in/F5oG9
function name:  test
number of ops:  35
compiled vars:  !0 = $function, !1 = $count, !2 = $arrayElements, !3 = $array, !4 = $timer, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      10000
          2        RECV_INIT                                        !2      1000
   35     3        ECHO                                                     !0
          4        ECHO                                                     '+...+'
   36     5        INIT_FCALL                                               'array_fill'
          6        SEND_VAL                                                 0
          7        SEND_VAR                                                 !2
          8        SEND_VAL                                                 'some+text+value'
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !3, $6
   37    11        INIT_FCALL                                               'microtime'
         12        SEND_VAL                                                 <true>
         13        DO_ICALL                                         $8      
         14        ASSIGN                                                   !4, $8
   38    15        ASSIGN                                                   !5, 0
         16      > JMP                                                      ->22
   39    17    >   INIT_DYNAMIC_CALL                                        !0
         18        SEND_VAR_EX                                              !3
         19        SEND_VAL_EX                                              'some_function'
         20        SEND_VAL_EX                                              'some+user+data'
         21        DO_FCALL                                      0          
   38    22    >   PRE_INC                                          ~12     !5
         23        IS_SMALLER                                               ~12, !1
         24      > JMPNZ                                                    ~13, ->17
   40    25    >   INIT_FCALL                                               'printf'
         26        SEND_VAL                                                 '%25.3f+sec%0A'
         27        INIT_FCALL                                               'microtime'
         28        SEND_VAL                                                 <true>
         29        DO_ICALL                                         $14     
         30        SUB                                              ~15     $14, !4
         31        SEND_VAL                                                 ~15
         32        DO_ICALL                                                 
   41    33      > RETURN                                                   !3
   42    34*     > RETURN                                                   null

End of function test

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.89 ms | 1408 KiB | 21 Q