3v4l.org

run code in 500+ PHP versions simultaneously
<?php $longString = 'I like apple. You like oranges. We like fruit. I like meat, also.'; $maxLineLength = 18; $words = explode(' ', $longString); $currentLength = 0; $index = 0; foreach ($words as $word) { // +1 because the word will receive back the space in the end that it loses in explode() $wordLength = strlen($word) + 1; if (($currentLength + $wordLength) <= $maxLineLength) { $output[$index] .= $word . ' '; $currentLength += $wordLength; } else { $index += 1; $currentLength = $wordLength; $output[$index] = $word; } } var_export($output);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 27
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 27
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 22
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/Ref5f
function name:  (null)
number of ops:  32
compiled vars:  !0 = $longString, !1 = $maxLineLength, !2 = $words, !3 = $currentLength, !4 = $index, !5 = $word, !6 = $wordLength, !7 = $output
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'I+like+apple.+You+like+oranges.+We+like+fruit.+I+like+meat%2C+also.'
    4     1        ASSIGN                                                       !1, 18
    6     2        INIT_FCALL                                                   'explode'
          3        SEND_VAL                                                     '+'
          4        SEND_VAR                                                     !0
          5        DO_ICALL                                             $10     
          6        ASSIGN                                                       !2, $10
    8     7        ASSIGN                                                       !3, 0
    9     8        ASSIGN                                                       !4, 0
   11     9      > FE_RESET_R                                           $14     !2, ->27
         10    > > FE_FETCH_R                                                   $14, !5, ->27
   13    11    >   STRLEN                                               ~15     !5
         12        ADD                                                  ~16     ~15, 1
         13        ASSIGN                                                       !6, ~16
   15    14        ADD                                                  ~18     !3, !6
         15        IS_SMALLER_OR_EQUAL                                          ~18, !1
         16      > JMPZ                                                         ~19, ->22
   16    17    >   CONCAT                                               ~21     !5, '+'
         18        ASSIGN_DIM_OP                    .=               8          !7, !4
         19        OP_DATA                                                      ~21
   17    20        ASSIGN_OP                                         1          !3, !6
   15    21      > JMP                                                          ->26
   19    22    >   ASSIGN_OP                                         1          !4, 1
   20    23        ASSIGN                                                       !3, !6
   21    24        ASSIGN_DIM                                                   !7, !4
         25        OP_DATA                                                      !5
   11    26    > > JMP                                                          ->10
         27    >   FE_FREE                                                      $14
   25    28        INIT_FCALL                                                   'var_export'
         29        SEND_VAR                                                     !7
         30        DO_ICALL                                                     
         31      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.71 ms | 2226 KiB | 15 Q