3v4l.org

run code in 500+ PHP versions simultaneously
<?php $originalString = "Hello world, what do you think of today's weather"; $findString = ' '; $nthOccurrence = 8; $newWord = 'beautiful '; function insertAfterNth($input, $find, $newString, $nth = 1) { $parts = explode($find, $input, $nth + 1); $parts[$nth] = $newString . $parts[$nth]; return implode($find, $parts); } echo insertAfterNth($originalString, $findString, $newWord, $nthOccurrence);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DOu9K
function name:  (null)
number of ops:  12
compiled vars:  !0 = $originalString, !1 = $findString, !2 = $nthOccurrence, !3 = $newWord
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'Hello+world%2C+what+do+you+think+of+today%27s+weather'
    4     1        ASSIGN                                                       !1, '+'
    5     2        ASSIGN                                                       !2, 8
    6     3        ASSIGN                                                       !3, 'beautiful+'
   14     4        INIT_FCALL                                                   'insertafternth'
          5        SEND_VAR                                                     !0
          6        SEND_VAR                                                     !1
          7        SEND_VAR                                                     !3
          8        SEND_VAR                                                     !2
          9        DO_FCALL                                          0  $8      
         10        ECHO                                                         $8
         11      > RETURN                                                       1

Function insertafternth:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DOu9K
function name:  insertAfterNth
number of ops:  18
compiled vars:  !0 = $input, !1 = $find, !2 = $newString, !3 = $nth, !4 = $parts
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
          3        RECV_INIT                                            !3      1
    9     4        INIT_FCALL                                                   'explode'
          5        SEND_VAR                                                     !1
          6        SEND_VAR                                                     !0
          7        ADD                                                  ~5      !3, 1
          8        SEND_VAL                                                     ~5
          9        DO_ICALL                                             $6      
         10        ASSIGN                                                       !4, $6
   10    11        FETCH_DIM_R                                          ~9      !4, !3
         12        CONCAT                                               ~10     !2, ~9
         13        ASSIGN_DIM                                                   !4, !3
         14        OP_DATA                                                      ~10
   11    15        FRAMELESS_ICALL_2                implode             ~11     !1, !4
         16      > RETURN                                                       ~11
   12    17*     > RETURN                                                       null

End of function insertafternth

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
202.37 ms | 1776 KiB | 15 Q