3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'a' => 'food', 'b' => 'foo', 'c' => 'goo', 'd' => 'foo', 'e' => 'good' ]; $needle = 'foo'; $newValue = 'bar'; function array_replace_value(&$ar, $value, $replacement) { $ar = preg_replace( '/^' . preg_quote($value, '/') . '$/', $replacement, $ar ); } array_replace_value($array, $needle, $newValue); var_export($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uutUI
function name:  (null)
number of ops:  12
compiled vars:  !0 = $array, !1 = $needle, !2 = $newValue
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, 'foo'
   12     2        ASSIGN                                                   !2, 'bar'
   23     3        INIT_FCALL                                               'array_replace_value'
          4        SEND_REF                                                 !0
          5        SEND_VAR                                                 !1
          6        SEND_VAR                                                 !2
          7        DO_FCALL                                      0          
   24     8        INIT_FCALL                                               'var_export'
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                                 
         11      > RETURN                                                   1

Function array_replace_value:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uutUI
function name:  array_replace_value
number of ops:  16
compiled vars:  !0 = $ar, !1 = $value, !2 = $replacement
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   16     3        INIT_FCALL                                               'preg_replace'
   17     4        INIT_FCALL                                               'preg_quote'
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 '%2F'
          7        DO_ICALL                                         $3      
          8        CONCAT                                           ~4      '%2F%5E', $3
          9        CONCAT                                           ~5      ~4, '%24%2F'
         10        SEND_VAL                                                 ~5
   18    11        SEND_VAR                                                 !2
   19    12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $6      
   16    14        ASSIGN                                                   !0, $6
   21    15      > RETURN                                                   null

End of function array_replace_value

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.12 ms | 1399 KiB | 20 Q