3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Arrays { /** * Replaces in all strings within a multidimensional array, even if objects are included * @param string $search search for this string * @param string $replace_with replace with this string * @param mixed $haystack Array or Object to search in all elements * @return mixed gives the same structure back */ public static function replace_everywhere($search, $replace_with, $haystack) { if (is_array($haystack) or is_object($haystack)) { // Arrays and Objects foreach ($haystack as &$value) { $value = Arrays::replace_everywhere($search, $replace_with, $value); } return $haystack; } elseif (is_string($haystack)) { // replace in a string element return str_replace($search, $replace_with, $haystack); } else { // other datatypes (e.g. integer) stay untouched return $haystack; } } } // You can call this like e.g. $a = array(true, 1, 'foo<bar', 'foo<baz', array("foo<loo"), (object) array('1' => 'foo<boo')); $a = Arrays::replace_everywhere("<", "&lt;", $a); var_export($a);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CDGvC
function name:  (null)
number of ops:  18
compiled vars:  !0 = $a
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   30     0  E >   INIT_ARRAY                                           ~1      <true>
          1        ADD_ARRAY_ELEMENT                                    ~1      1
          2        ADD_ARRAY_ELEMENT                                    ~1      'foo%3Cbar'
          3        ADD_ARRAY_ELEMENT                                    ~1      'foo%3Cbaz'
          4        ADD_ARRAY_ELEMENT                                    ~1      <array>
          5        CAST                                              8  ~2      <array>
          6        ADD_ARRAY_ELEMENT                                    ~1      ~2
          7        ASSIGN                                                       !0, ~1
   31     8        INIT_STATIC_METHOD_CALL                                      'Arrays', 'replace_everywhere'
          9        SEND_VAL                                                     '%3C'
         10        SEND_VAL                                                     '%26lt%3B'
         11        SEND_VAR                                                     !0
         12        DO_FCALL                                          0  $4      
         13        ASSIGN                                                       !0, $4
   32    14        INIT_FCALL                                                   'var_export'
         15        SEND_VAR                                                     !0
         16        DO_ICALL                                                     
         17      > RETURN                                                       1

Class Arrays:
Function replace_everywhere:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 7
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 20
Branch analysis from position: 8
2 jumps found. (Code = 125) Position 1 = 9, Position 2 = 17
Branch analysis from position: 9
2 jumps found. (Code = 126) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/CDGvC
function name:  replace_everywhere
number of ops:  28
compiled vars:  !0 = $search, !1 = $replace_with, !2 = $haystack, !3 = $value
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   12     3        TYPE_CHECK                                      128  ~4      !2
          4      > JMPNZ_EX                                             ~4      ~4, ->7
          5    >   TYPE_CHECK                                      256  ~5      !2
          6        BOOL                                                 ~4      ~5
          7    > > JMPZ                                                         ~4, ->20
   14     8    > > FE_RESET_RW                                          $6      !2, ->17
          9    > > FE_FETCH_RW                                                  $6, !3, ->17
   15    10    >   INIT_STATIC_METHOD_CALL                                      'Arrays', 'replace_everywhere'
         11        SEND_VAR                                                     !0
         12        SEND_VAR                                                     !1
         13        SEND_VAR                                                     !3
         14        DO_FCALL                                          0  $7      
         15        ASSIGN                                                       !3, $7
   14    16      > JMP                                                          ->9
         17    >   FE_FREE                                                      $6
   17    18      > RETURN                                                       !2
   12    19*       JMP                                                          ->27
   18    20    >   TYPE_CHECK                                       64          !2
         21      > JMPZ                                                         ~9, ->26
   20    22    >   FRAMELESS_ICALL_3                str_replace         ~10     !0, !1
         23        OP_DATA                                                      !2
         24      > RETURN                                                       ~10
   18    25*       JMP                                                          ->27
   23    26    > > RETURN                                                       !2
   25    27*     > RETURN                                                       null

End of function replace_everywhere

End of class Arrays.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
183.11 ms | 1482 KiB | 14 Q