3v4l.org

run code in 500+ PHP versions simultaneously
<?php function formatStrings($strings, $positions) { $position = 0; foreach ($strings as $key => $str) { // do we need to move to a new position to display the next string? if ($positions[$key]['position'] > $position) { echo str_pad('', $positions[$key]['position'] - $position - 1); $position = $positions[$key]['position']; } // display the string echo str_pad($str, $positions[$key]['width']); $position += $positions[$key]['width'] - 1; } } $strings = array('ETL','E7954','20181123'); $positions = array(array('position' => 20, 'width' => 9), array('position' => 48, 'width' => 14), array('position' => 64, 'width' => 8)); echo " 1 2 3 4 5 6 7\n"; echo "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"; echo formatStrings($strings, $positions);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/oQH6R
function name:  (null)
number of ops:  10
compiled vars:  !0 = $strings, !1 = $positions
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                       !0, <array>
   17     1        ASSIGN                                                       !1, <array>
   20     2        ECHO                                                         '+++++++++1+++++++++2+++++++++3+++++++++4+++++++++5+++++++++6+++++++++7%0A'
   21     3        ECHO                                                         '12345678901234567890123456789012345678901234567890123456789012345678901234567890%0A'
   22     4        INIT_FCALL                                                   'formatstrings'
          5        SEND_VAR                                                     !0
          6        SEND_VAR                                                     !1
          7        DO_FCALL                                          0  $4      
          8        ECHO                                                         $4
          9      > RETURN                                                       1

Function formatstrings:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 34
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 34
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 22
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 22
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/oQH6R
function name:  formatStrings
number of ops:  36
compiled vars:  !0 = $strings, !1 = $positions, !2 = $position, !3 = $str, !4 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    3     2        ASSIGN                                                       !2, 0
    4     3      > FE_RESET_R                                           $6      !0, ->34
          4    > > FE_FETCH_R                                           ~7      $6, !3, ->34
          5    >   ASSIGN                                                       !4, ~7
    6     6        FETCH_DIM_R                                          ~9      !1, !4
          7        FETCH_DIM_R                                          ~10     ~9, 'position'
          8        IS_SMALLER                                                   !2, ~10
          9      > JMPZ                                                         ~11, ->22
    7    10    >   INIT_FCALL                                                   'str_pad'
         11        SEND_VAL                                                     ''
         12        FETCH_DIM_R                                          ~12     !1, !4
         13        FETCH_DIM_R                                          ~13     ~12, 'position'
         14        SUB                                                  ~14     ~13, !2
         15        SUB                                                  ~15     ~14, 1
         16        SEND_VAL                                                     ~15
         17        DO_ICALL                                             $16     
         18        ECHO                                                         $16
    8    19        FETCH_DIM_R                                          ~17     !1, !4
         20        FETCH_DIM_R                                          ~18     ~17, 'position'
         21        ASSIGN                                                       !2, ~18
   11    22    >   INIT_FCALL                                                   'str_pad'
         23        SEND_VAR                                                     !3
         24        FETCH_DIM_R                                          ~20     !1, !4
         25        FETCH_DIM_R                                          ~21     ~20, 'width'
         26        SEND_VAL                                                     ~21
         27        DO_ICALL                                             $22     
         28        ECHO                                                         $22
   12    29        FETCH_DIM_R                                          ~23     !1, !4
         30        FETCH_DIM_R                                          ~24     ~23, 'width'
         31        SUB                                                  ~25     ~24, 1
         32        ASSIGN_OP                                         1          !2, ~25
    4    33      > JMP                                                          ->4
         34    >   FE_FREE                                                      $6
   14    35      > RETURN                                                       null

End of function formatstrings

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
133.81 ms | 2201 KiB | 15 Q