3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr = array( "key1"=>"value1", "key2"=>null, "key3"=>array( "subkey1"=>null, "subkey2"=>"subvalue2"), "key4"=>null); echo json_encode(replace_null_with_empty_string($arr)); function replace_null_with_empty_string($array) { foreach ($array as $key => $value) { if(is_array($value)) $array[$key] = replace_null_with_empty_string($value); else { if (is_null($value)) $array[$key] = ""; } } return $array; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7uXTL
function name:  (null)
number of ops:  9
compiled vars:  !0 = $arr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   10     1        INIT_FCALL                                                   'json_encode'
          2        INIT_FCALL_BY_NAME                                           'replace_null_with_empty_string'
          3        SEND_VAR_EX                                                  !0
          4        DO_FCALL                                          0  $2      
          5        SEND_VAR                                                     $2
          6        DO_ICALL                                             $3      
          7        ECHO                                                         $3
   25     8      > RETURN                                                       1

Function replace_null_with_empty_string:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 17
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 12
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 16
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/7uXTL
function name:  replace_null_with_empty_string
number of ops:  20
compiled vars:  !0 = $array, !1 = $value, !2 = $key
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV                                                 !0      
   14     1      > FE_RESET_R                                           $3      !0, ->17
          2    > > FE_FETCH_R                                           ~4      $3, !1, ->17
          3    >   ASSIGN                                                       !2, ~4
   16     4        TYPE_CHECK                                      128          !1
          5      > JMPZ                                                         ~6, ->12
   17     6    >   INIT_FCALL_BY_NAME                                           'replace_null_with_empty_string'
          7        SEND_VAR_EX                                                  !1
          8        DO_FCALL                                          0  $8      
          9        ASSIGN_DIM                                                   !0, !2
         10        OP_DATA                                                      $8
   16    11      > JMP                                                          ->16
   20    12    >   TYPE_CHECK                                        2          !1
         13      > JMPZ                                                         ~9, ->16
   21    14    >   ASSIGN_DIM                                                   !0, !2
         15        OP_DATA                                                      ''
   14    16    > > JMP                                                          ->2
         17    >   FE_FREE                                                      $3
   24    18      > RETURN                                                       !0
   25    19*     > RETURN                                                       null

End of function replace_null_with_empty_string

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
175.28 ms | 3337 KiB | 13 Q