3v4l.org

run code in 300+ PHP versions simultaneously
<?php $raw = array( 'firstname' => 'Foo', 'lastname' => 'Bar', 'nickname' => '', 'birthdate' => [ 'day' => '', 'month' => '', 'year' => '', ], 'likes' => [ 'cars' => ['Subaru Impreza WRX STi', 'Mitsubishi Evo', 'Nissan GTR'], 'bikes' => [], ], 'zero' => 0, 'deeper' => [ 'zeroString' => '0', 'null' => null ], 'false' => false, ); function recursivelyRemoveEmpties(array $array): array { foreach ($array as $key => &$value) { if (is_array($value)) { $value = recursivelyRemoveEmpties($value); if (!$value) { unset($array[$key]); } continue; } if ($value === '') { unset($array[$key]); } } return $array; } var_export(recursivelyRemoveEmpties($raw));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gRg1b
function name:  (null)
number of ops:  8
compiled vars:  !0 = $raw
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   43     1        INIT_FCALL                                               'var_export'
          2        INIT_FCALL                                               'recursivelyremoveempties'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function recursivelyremoveempties:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 2, Position 2 = 18
Branch analysis from position: 2
2 jumps found. (Code = 126) Position 1 = 3, Position 2 = 18
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 14
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 13
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 17
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/gRg1b
function name:  recursivelyRemoveEmpties
number of ops:  23
compiled vars:  !0 = $array, !1 = $value, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   27     1      > FE_RESET_RW                                      $3      !0, ->18
          2    > > FE_FETCH_RW                                      ~4      $3, !1, ->18
          3    >   ASSIGN                                                   !2, ~4
   28     4        TYPE_CHECK                                  128          !1
          5      > JMPZ                                                     ~6, ->14
   29     6    >   INIT_FCALL_BY_NAME                                       'recursivelyRemoveEmpties'
          7        SEND_VAR_EX                                              !1
          8        DO_FCALL                                      0  $7      
          9        ASSIGN                                                   !1, $7
   30    10        BOOL_NOT                                         ~9      !1
         11      > JMPZ                                                     ~9, ->13
   31    12    >   UNSET_DIM                                                !0, !2
   33    13    > > JMP                                                      ->2
   35    14    >   IS_IDENTICAL                                             !1, ''
         15      > JMPZ                                                     ~10, ->17
   36    16    >   UNSET_DIM                                                !0, !2
   27    17    > > JMP                                                      ->2
         18    >   FE_FREE                                                  $3
   40    19        VERIFY_RETURN_TYPE                                       !0
         20      > RETURN                                                   !0
   41    21*       VERIFY_RETURN_TYPE                                       
         22*     > RETURN                                                   null

End of function recursivelyremoveempties

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.8 ms | 1009 KiB | 15 Q