3v4l.org

run code in 300+ 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 = 22
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/O1kBl
function name:  getReplacedStr
number of ops:  25
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, ->22
    6    14    >   CONCAT                                           ~11     !2, '+'
         15        INIT_FCALL                                               'implode'
         16        SEND_VAL                                                 '+'
         17        SEND_VAR                                                 !3
         18        DO_ICALL                                         $12     
         19        CONCAT                                           ~13     ~11, $12
         20        ASSIGN                                                   !5, ~13
    5    21      > JMP                                                      ->23
    8    22    >   ASSIGN                                                   !5, !0
   10    23    > > RETURN                                                   !5
   11    24*     > RETURN                                                   null

End of function getreplacedstr

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.3 ms | 1454 KiB | 18 Q