3v4l.org

run code in 500+ PHP versions simultaneously
<?php final class ArrayCleaner { public static function clean(array $value): array { foreach ($value as $k => $v) { if (\is_array($v)) { $value[$k] = self::clean($v); if (0 == \count($value[$k])) { unset($value[$k]); } } elseif (empty($v)) { unset($value[$k]); } } return $value; } } $input = [ 'empty_string_to_remove' => '', 'empty_int_to_remove' => 0, 'empty_string_number_to_remove' => '0', 'value_to_keep' => 5, 'empty_array_to_remove' => [], 'empty_array_of_empty_arrays_to_remove' => [ 'one' => [], 'two' => [], 'three' => [false, null, '0'], ], 'array_to_keep_1' => [ 'value' => 1, ], 'array_to_keep_2' => [ 'empty_to_remove' => [], 'array_to_keep' => ['yes'], ], ]; print_r(ArrayCleaner::clean($input));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9Zt7A
function name:  (null)
number of ops:  8
compiled vars:  !0 = $input
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                       !0, <array>
   43     1        INIT_FCALL                                                   'print_r'
          2        INIT_STATIC_METHOD_CALL                                      'ArrayCleaner', 'clean'
          3        SEND_VAR                                                     !0
          4        DO_FCALL                                          0  $2      
          5        SEND_VAR                                                     $2
          6        DO_ICALL                                                     
          7      > RETURN                                                       1

Class ArrayCleaner:
Function clean:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 21
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 21
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 17
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 16
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 20
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/9Zt7A
function name:  clean
number of ops:  26
compiled vars:  !0 = $value, !1 = $v, !2 = $k
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E >   RECV                                                 !0      
    7     1      > FE_RESET_R                                           $3      !0, ->21
          2    > > FE_FETCH_R                                           ~4      $3, !1, ->21
          3    >   ASSIGN                                                       !2, ~4
    8     4        TYPE_CHECK                                      128          !1
          5      > JMPZ                                                         ~6, ->17
    9     6    >   INIT_STATIC_METHOD_CALL                                      'clean'
          7        SEND_VAR                                                     !1
          8        DO_FCALL                                          0  $8      
          9        ASSIGN_DIM                                                   !0, !2
         10        OP_DATA                                                      $8
   11    11        FETCH_DIM_R                                          ~9      !0, !2
         12        COUNT                                                ~10     ~9
         13        IS_EQUAL                                                     ~10, 0
         14      > JMPZ                                                         ~11, ->16
   12    15    >   UNSET_DIM                                                    !0, !2
    8    16    > > JMP                                                          ->20
   14    17    >   ISSET_ISEMPTY_CV                                             !1
         18      > JMPZ                                                         ~12, ->20
   15    19    >   UNSET_DIM                                                    !0, !2
    7    20    > > JMP                                                          ->2
         21    >   FE_FREE                                                      $3
   19    22        VERIFY_RETURN_TYPE                                           !0
         23      > RETURN                                                       !0
   20    24*       VERIFY_RETURN_TYPE                                           
         25*     > RETURN                                                       null

End of function clean

End of class ArrayCleaner.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
158.5 ms | 2163 KiB | 14 Q