3v4l.org

run code in 300+ PHP versions simultaneously
<?php $id = [11,12,13]; $code = ['1234','5678','9012']; $qty = [3,4,5]; $amount = [12.34,23.45,34.56]; //dry run to cache function calls $op = '%s executed in %.8f seconds'; microtime(true); $max = count($id); $start = $end = 0; $data = []; for ($i=0; $i<$max; $i++) { $data[] = [ 'id' => $id[$i], 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; } $data = []; foreach($id as $i => $v) { $data[] = [ 'id' => $v, 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; } $data = array_map(function($a, $b, $c, $d) { return [ 'id' => $a, 'code' => $b, 'qty' => $c, 'amount' => $d ]; }, $id, $code, $qty, $amount); //end dry-run $start = microtime(true); $data = []; foreach($id as $i => $v) { $data[] = [ 'id' => $v, 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; } $end = microtime(true); printf($op, 'foreach', $end - $start); echo PHP_EOL; //---- $start = microtime(true); $max = count($id); $data = []; for ($i=0; $i<$max; $i++) { $data[] = [ 'id' => $id[$i], 'code' => $code[$i], 'qty' => $qty[$i], 'amount' => $amount[$i] ]; } $end = microtime(true); printf($op, 'for', $end - $start); echo PHP_EOL; $start = microtime(true); $data = array_map(function($a, $b, $c, $d) { return [ 'id' => $a, 'code' => $b, 'qty' => $c, 'amount' => $d ]; }, $id, $code, $qty, $amount); $end = microtime(true); printf($op, 'array_map', $end - $start);
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 = 28, Position 2 = 15
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 42
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 42
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 42
2 jumps found. (Code = 77) Position 1 = 58, Position 2 = 70
Branch analysis from position: 58
2 jumps found. (Code = 78) Position 1 = 59, Position 2 = 70
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
Branch analysis from position: 70
1 jumps found. (Code = 42) Position 1 = 102
Branch analysis from position: 102
2 jumps found. (Code = 44) Position 1 = 104, Position 2 = 91
Branch analysis from position: 104
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 91
2 jumps found. (Code = 44) Position 1 = 104, Position 2 = 91
Branch analysis from position: 104
Branch analysis from position: 91
Branch analysis from position: 70
Branch analysis from position: 42
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 15
Branch analysis from position: 28
Branch analysis from position: 15
filename:       /in/ejIl5
function name:  (null)
number of ops:  139
compiled vars:  !0 = $id, !1 = $code, !2 = $qty, !3 = $amount, !4 = $op, !5 = $max, !6 = $start, !7 = $end, !8 = $data, !9 = $i, !10 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, <array>
    6     3        ASSIGN                                                   !3, <array>
    9     4        ASSIGN                                                   !4, '%25s+executed+in+%25.8f+seconds'
   10     5        INIT_FCALL                                               'microtime'
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                                 
   11     8        COUNT                                            ~17     !0
          9        ASSIGN                                                   !5, ~17
   12    10        ASSIGN                                           ~19     !7, 0
         11        ASSIGN                                                   !6, ~19
   13    12        ASSIGN                                                   !8, <array>
   14    13        ASSIGN                                                   !9, 0
         14      > JMP                                                      ->26
   16    15    >   FETCH_DIM_R                                      ~24     !0, !9
         16        INIT_ARRAY                                       ~25     ~24, 'id'
   17    17        FETCH_DIM_R                                      ~26     !1, !9
         18        ADD_ARRAY_ELEMENT                                ~25     ~26, 'code'
   18    19        FETCH_DIM_R                                      ~27     !2, !9
         20        ADD_ARRAY_ELEMENT                                ~25     ~27, 'qty'
   19    21        FETCH_DIM_R                                      ~28     !3, !9
         22        ADD_ARRAY_ELEMENT                                ~25     ~28, 'amount'
   15    23        ASSIGN_DIM                                               !8
   19    24        OP_DATA                                                  ~25
   14    25        PRE_INC                                                  !9
         26    >   IS_SMALLER                                               !9, !5
         27      > JMPNZ                                                    ~30, ->15
   22    28    >   ASSIGN                                                   !8, <array>
   23    29      > FE_RESET_R                                       $32     !0, ->42
         30    > > FE_FETCH_R                                       ~33     $32, !10, ->42
         31    >   ASSIGN                                                   !9, ~33
   25    32        INIT_ARRAY                                       ~36     !10, 'id'
   26    33        FETCH_DIM_R                                      ~37     !1, !9
         34        ADD_ARRAY_ELEMENT                                ~36     ~37, 'code'
   27    35        FETCH_DIM_R                                      ~38     !2, !9
         36        ADD_ARRAY_ELEMENT                                ~36     ~38, 'qty'
   28    37        FETCH_DIM_R                                      ~39     !3, !9
         38        ADD_ARRAY_ELEMENT                                ~36     ~39, 'amount'
   24    39        ASSIGN_DIM                                               !8
   28    40        OP_DATA                                                  ~36
   23    41      > JMP                                                      ->30
         42    >   FE_FREE                                                  $32
   31    43        INIT_FCALL                                               'array_map'
         44        DECLARE_LAMBDA_FUNCTION                          ~40     [0]
   38    45        SEND_VAL                                                 ~40
         46        SEND_VAR                                                 !0
         47        SEND_VAR                                                 !1
         48        SEND_VAR                                                 !2
         49        SEND_VAR                                                 !3
   31    50        DO_ICALL                                         $41     
         51        ASSIGN                                                   !8, $41
   42    52        INIT_FCALL                                               'microtime'
         53        SEND_VAL                                                 <true>
         54        DO_ICALL                                         $43     
         55        ASSIGN                                                   !6, $43
   44    56        ASSIGN                                                   !8, <array>
   45    57      > FE_RESET_R                                       $46     !0, ->70
         58    > > FE_FETCH_R                                       ~47     $46, !10, ->70
         59    >   ASSIGN                                                   !9, ~47
   47    60        INIT_ARRAY                                       ~50     !10, 'id'
   48    61        FETCH_DIM_R                                      ~51     !1, !9
         62        ADD_ARRAY_ELEMENT                                ~50     ~51, 'code'
   49    63        FETCH_DIM_R                                      ~52     !2, !9
         64        ADD_ARRAY_ELEMENT                                ~50     ~52, 'qty'
   50    65        FETCH_DIM_R                                      ~53     !3, !9
         66        ADD_ARRAY_ELEMENT                                ~50     ~53, 'amount'
   46    67        ASSIGN_DIM                                               !8
   50    68        OP_DATA                                                  ~50
   45    69      > JMP                                                      ->58
         70    >   FE_FREE                                                  $46
   54    71        INIT_FCALL                                               'microtime'
         72        SEND_VAL                                                 <true>
         73        DO_ICALL                                         $54     
         74        ASSIGN                                                   !7, $54
   55    75        INIT_FCALL                                               'printf'
         76        SEND_VAR                                                 !4
         77        SEND_VAL                                                 'foreach'
         78        SUB                                              ~56     !7, !6
         79        SEND_VAL                                                 ~56
         80        DO_ICALL                                                 
   57    81        ECHO                                                     '%0A'
   60    82        INIT_FCALL                                               'microtime'
         83        SEND_VAL                                                 <true>
         84        DO_ICALL                                         $58     
         85        ASSIGN                                                   !6, $58
   62    86        COUNT                                            ~60     !0
         87        ASSIGN                                                   !5, ~60
   63    88        ASSIGN                                                   !8, <array>
   64    89        ASSIGN                                                   !9, 0
         90      > JMP                                                      ->102
   66    91    >   FETCH_DIM_R                                      ~65     !0, !9
         92        INIT_ARRAY                                       ~66     ~65, 'id'
   67    93        FETCH_DIM_R                                      ~67     !1, !9
         94        ADD_ARRAY_ELEMENT                                ~66     ~67, 'code'
   68    95        FETCH_DIM_R                                      ~68     !2, !9
         96        ADD_ARRAY_ELEMENT                                ~66     ~68, 'qty'
   69    97        FETCH_DIM_R                                      ~69     !3, !9
         98        ADD_ARRAY_ELEMENT                                ~66     ~69, 'amount'
   65    99        ASSIGN_DIM                                               !8
   69   100        OP_DATA                                                  ~66
   64   101        PRE_INC                                                  !9
        102    >   IS_SMALLER                                               !9, !5
        103      > JMPNZ                                                    ~71, ->91
   73   104    >   INIT_FCALL                                               'microtime'
        105        SEND_VAL                                                 <true>
        106        DO_ICALL                                         $72     
        107        ASSIGN                                                   !7, $72
   74   108        INIT_FCALL                                               'printf'
        109        SEND_VAR                                                 !4
        110        SEND_VAL                                                 'for'
        111        SUB                                              ~74     !7, !6
        112        SEND_VAL                                                 ~74
        113        DO_ICALL                                                 
   76   114        ECHO                                                     '%0A'
   78   115        INIT_FCALL                                               'microtime'
        116        SEND_VAL                                                 <true>
        117        DO_ICALL                                         $76     
        118        ASSIGN                                                   !6, $76
   80   119        INIT_FCALL                                               'array_map'
        120        DECLARE_LAMBDA_FUNCTION                          ~78     [1]
   87   121        SEND_VAL                                                 ~78
        122        SEND_VAR                                                 !0
        123        SEND_VAR                                                 !1
        124        SEND_VAR                                                 !2
        125        SEND_VAR                                                 !3
   80   126        DO_ICALL                                         $79     
        127        ASSIGN                                                   !8, $79
   89   128        INIT_FCALL                                               'microtime'
        129        SEND_VAL                                                 <true>
        130        DO_ICALL                                         $81     
        131        ASSIGN                                                   !7, $81
   90   132        INIT_FCALL                                               'printf'
        133        SEND_VAR                                                 !4
        134        SEND_VAL                                                 'array_map'
        135        SUB                                              ~83     !7, !6
        136        SEND_VAL                                                 ~83
        137        DO_ICALL                                                 
        138      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ejIl5
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $a, !1 = $b, !2 = $c, !3 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   33     4        INIT_ARRAY                                       ~4      !0, 'id'
   34     5        ADD_ARRAY_ELEMENT                                ~4      !1, 'code'
   35     6        ADD_ARRAY_ELEMENT                                ~4      !2, 'qty'
   36     7        ADD_ARRAY_ELEMENT                                ~4      !3, 'amount'
          8      > RETURN                                                   ~4
   38     9*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ejIl5
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $a, !1 = $b, !2 = $c, !3 = $d
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
   82     4        INIT_ARRAY                                       ~4      !0, 'id'
   83     5        ADD_ARRAY_ELEMENT                                ~4      !1, 'code'
   84     6        ADD_ARRAY_ELEMENT                                ~4      !2, 'qty'
   85     7        ADD_ARRAY_ELEMENT                                ~4      !3, 'amount'
          8      > RETURN                                                   ~4
   87     9*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
145.46 ms | 1017 KiB | 16 Q