3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = "PHP CODING TECH"; $counters = array_fill_keys(explode(' ', $input), 1); // ['PHP' => 1, 'CODING' => 1, 'TECH' => 1] $bump = false; // permit outer loop to run while (!$bump) { // while still letters to output.... $bump = true; // stop after this iteration unless more letters to output foreach ($counters as $word => &$len) { // $len is mod-by-ref for incrementing echo substr($word, 0, $len); // echo letters using $len if ($bump && isset($word[$len])) { // if no $len has been incremented during inner loop... ++$len; // increment this word's $len $bump = false; // permit outer loop to run again } } echo "\n"; // separate outputs }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 12
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 125) Position 1 = 14, Position 2 = 29
Branch analysis from position: 14
2 jumps found. (Code = 126) Position 1 = 15, Position 2 = 29
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 28
Branch analysis from position: 25
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 12
Branch analysis from position: 33
Branch analysis from position: 12
Branch analysis from position: 29
filename:       /in/fUg7p
function name:  (null)
number of ops:  34
compiled vars:  !0 = $input, !1 = $counters, !2 = $bump, !3 = $len, !4 = $word
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'PHP+CODING+TECH'
    3     1        INIT_FCALL                                               'array_fill_keys'
          2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $6      
          6        SEND_VAR                                                 $6
          7        SEND_VAL                                                 1
          8        DO_ICALL                                         $7      
          9        ASSIGN                                                   !1, $7
    5    10        ASSIGN                                                   !2, <false>
    6    11      > JMP                                                      ->31
    7    12    >   ASSIGN                                                   !2, <true>
    8    13      > FE_RESET_RW                                      $11     !1, ->29
         14    > > FE_FETCH_RW                                      ~12     $11, !3, ->29
         15    >   ASSIGN                                                   !4, ~12
    9    16        INIT_FCALL                                               'substr'
         17        SEND_VAR                                                 !4
         18        SEND_VAL                                                 0
         19        SEND_VAR                                                 !3
         20        DO_ICALL                                         $14     
         21        ECHO                                                     $14
   10    22      > JMPZ_EX                                          ~15     !2, ->25
         23    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~16     !4, !3
         24        BOOL                                             ~15     ~16
         25    > > JMPZ                                                     ~15, ->28
   11    26    >   PRE_INC                                                  !3
   12    27        ASSIGN                                                   !2, <false>
    8    28    > > JMP                                                      ->14
         29    >   FE_FREE                                                  $11
   15    30        ECHO                                                     '%0A'
    6    31    >   BOOL_NOT                                         ~19     !2
         32      > JMPNZ                                                    ~19, ->12
   16    33    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.85 ms | 1017 KiB | 16 Q