3v4l.org

run code in 500+ PHP versions simultaneously
<?php function getReplacedStr($str, $searchStr, $replaceWith){ $arr = explode(' ', $str); $firstElement = array_shift($arr); if($searchStr == $firstElement){ $finalStr = $replaceWith.' '.implode(' ', $arr); }else{ $finalStr = $str; } return $finalStr; } $replaceWith = 'Hi'; $searchStr = 'Hello'; $str = 'Hello World Hello World'; $str2 = 'Super World Hello World'; echo getReplacedStr($str, $searchStr, $replaceWith); echo "\n"; echo getReplacedStr($str2, $searchStr, $replaceWith);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/O1kBl
function name:  (null)
number of ops:  18
compiled vars:  !0 = $replaceWith, !1 = $searchStr, !2 = $str, !3 = $str2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   ASSIGN                                                       !0, 'Hi'
   13     1        ASSIGN                                                       !1, 'Hello'
   14     2        ASSIGN                                                       !2, 'Hello+World+Hello+World'
   15     3        ASSIGN                                                       !3, 'Super+World+Hello+World'
   17     4        INIT_FCALL                                                   'getreplacedstr'
          5        SEND_VAR                                                     !2
          6        SEND_VAR                                                     !1
          7        SEND_VAR                                                     !0
          8        DO_FCALL                                          0  $8      
          9        ECHO                                                         $8
   18    10        ECHO                                                         '%0A'
   19    11        INIT_FCALL                                                   'getreplacedstr'
         12        SEND_VAR                                                     !3
         13        SEND_VAR                                                     !1
         14        SEND_VAR                                                     !0
         15        DO_FCALL                                          0  $9      
         16        ECHO                                                         $9
         17      > RETURN                                                       1

Function getreplacedstr:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/O1kBl
function name:  getReplacedStr
number of ops:  22
compiled vars:  !0 = $str, !1 = $searchStr, !2 = $replaceWith, !3 = $arr, !4 = $firstElement, !5 = $finalStr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
    3     3        INIT_FCALL                                                   'explode'
          4        SEND_VAL                                                     '+'
          5        SEND_VAR                                                     !0
          6        DO_ICALL                                             $6      
          7        ASSIGN                                                       !3, $6
    4     8        INIT_FCALL                                                   'array_shift'
          9        SEND_REF                                                     !3
         10        DO_ICALL                                             $8      
         11        ASSIGN                                                       !4, $8
    5    12        IS_EQUAL                                                     !1, !4
         13      > JMPZ                                                         ~10, ->19
    6    14    >   CONCAT                                               ~11     !2, '+'
         15        FRAMELESS_ICALL_2                implode             ~12     '+', !3
         16        CONCAT                                               ~13     ~11, ~12
         17        ASSIGN                                                       !5, ~13
    5    18      > JMP                                                          ->20
    8    19    >   ASSIGN                                                       !5, !0
   10    20    > > RETURN                                                       !5
   11    21*     > RETURN                                                       null

End of function getreplacedstr

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
168.84 ms | 2598 KiB | 17 Q