3v4l.org

run code in 300+ PHP versions simultaneously
<?php class RecursionImplementation { public static function recursionInitiator($array, $keylist) { self::$keys = explode(",", $keylist); if(is_null(self::keys) || count(self::$keys) == 0) return $array; $array = self::recursion($array); return $array; } private static function recursion($array) { $all_keys = array_keys($array); $intersection = array_intersect($all_keys, self::$keys); $difference = array_diff($all_keys, self::$keys); $number_of_intersecting_keys = count($intersection); $number_of_non_intersecting_keys = count($array) - $number_of_intersecting_keys; if($number_of_intersecting_keys + $number_of_non_intersecting_keys == 0) return; if($number_of_intersecting_keys >= 1) { foreach($intersection as $key) { unset($array[$key]); $array[$key] = self::$asterisk; } } if($number_of_non_intersecting_keys >= 1) { foreach($difference as $key) { if(is_array($array[$key])) { $value = self::recursion($array[$key]); unset($array[$key]); $array[$key] = $value; } } } return $array; } private static $keys; private static $asterisk = "**"; } $information = array("login" => "someUsername", "password" => "somePassword", "card_pin"=>"card_1234", "pin"=>"pin_356", "iin" => "iin_123", "shipping" => array("value" => array("telephone" => array("inner_value" => "telephone_998"))), "cardnumber" => "card_number_876", "customer_id" => "customer_654", "telephone" => "someOtherTelephoneNumber555"); $list = "telephone,login"; print_r($information); echo "\n\n"; $final_array = RecursionImplementation::recursionInitiator($information, $list); print_r($final_array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KBmA3
function name:  (null)
number of ops:  15
compiled vars:  !0 = $information, !1 = $list, !2 = $final_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   57     0  E >   ASSIGN                                                   !0, <array>
   66     1        ASSIGN                                                   !1, 'telephone%2Clogin'
   68     2        INIT_FCALL                                               'print_r'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
   69     5        ECHO                                                     '%0A%0A'
   70     6        INIT_STATIC_METHOD_CALL                                  'RecursionImplementation', 'recursionInitiator'
          7        SEND_VAR                                                 !0
          8        SEND_VAR                                                 !1
          9        DO_FCALL                                      0  $6      
         10        ASSIGN                                                   !2, $6
   71    11        INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                                 
         14      > RETURN                                                   1

Class RecursionImplementation:
Function recursioninitiator:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/KBmA3
function name:  recursionInitiator
number of ops:  23
compiled vars:  !0 = $array, !1 = $keylist
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    7     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '%2C'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $3      
          6        ASSIGN_STATIC_PROP                                       'keys'
          7        OP_DATA                                                  $3
    9     8        FETCH_CLASS_CONSTANT                             ~4      'keys'
          9        TYPE_CHECK                                    2  ~5      ~4
         10      > JMPNZ_EX                                         ~5      ~5, ->15
         11    >   FETCH_STATIC_PROP_R          unknown             ~6      'keys'
         12        COUNT                                            ~7      ~6
         13        IS_EQUAL                                         ~8      ~7, 0
         14        BOOL                                             ~5      ~8
         15    > > JMPZ                                                     ~5, ->17
   10    16    > > RETURN                                                   !0
   12    17    >   INIT_STATIC_METHOD_CALL                                  'recursion'
         18        SEND_VAR_EX                                              !0
         19        DO_FCALL                                      0  $9      
         20        ASSIGN                                                   !0, $9
   13    21      > RETURN                                                   !0
   14    22*     > RETURN                                                   null

End of function recursioninitiator

Function recursion:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 26
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 36
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 35
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 35
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 53
Branch analysis from position: 38
2 jumps found. (Code = 77) Position 1 = 39, Position 2 = 52
Branch analysis from position: 39
2 jumps found. (Code = 78) Position 1 = 40, Position 2 = 52
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 51
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 51
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
Branch analysis from position: 53
Branch analysis from position: 35
Branch analysis from position: 36
filename:       /in/KBmA3
function name:  recursion
number of ops:  55
compiled vars:  !0 = $array, !1 = $all_keys, !2 = $intersection, !3 = $difference, !4 = $number_of_intersecting_keys, !5 = $number_of_non_intersecting_keys, !6 = $key, !7 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   18     1        INIT_FCALL                                               'array_keys'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $8      
          4        ASSIGN                                                   !1, $8
   19     5        INIT_FCALL                                               'array_intersect'
          6        SEND_VAR                                                 !1
          7        FETCH_STATIC_PROP_R          unknown             ~10     'keys'
          8        SEND_VAL                                                 ~10
          9        DO_ICALL                                         $11     
         10        ASSIGN                                                   !2, $11
   20    11        INIT_FCALL                                               'array_diff'
         12        SEND_VAR                                                 !1
         13        FETCH_STATIC_PROP_R          unknown             ~13     'keys'
         14        SEND_VAL                                                 ~13
         15        DO_ICALL                                         $14     
         16        ASSIGN                                                   !3, $14
   22    17        COUNT                                            ~16     !2
         18        ASSIGN                                                   !4, ~16
   23    19        COUNT                                            ~18     !0
         20        SUB                                              ~19     ~18, !4
         21        ASSIGN                                                   !5, ~19
   25    22        ADD                                              ~21     !4, !5
         23        IS_EQUAL                                                 ~21, 0
         24      > JMPZ                                                     ~22, ->26
   26    25    > > RETURN                                                   null
   28    26    >   IS_SMALLER_OR_EQUAL                                      1, !4
         27      > JMPZ                                                     ~23, ->36
   30    28    > > FE_RESET_R                                       $24     !2, ->35
         29    > > FE_FETCH_R                                               $24, !6, ->35
   32    30    >   UNSET_DIM                                                !0, !6
   33    31        FETCH_STATIC_PROP_R          unknown             ~26     'asterisk'
         32        ASSIGN_DIM                                               !0, !6
         33        OP_DATA                                                  ~26
   30    34      > JMP                                                      ->29
         35    >   FE_FREE                                                  $24
   37    36    >   IS_SMALLER_OR_EQUAL                                      1, !5
         37      > JMPZ                                                     ~27, ->53
   39    38    > > FE_RESET_R                                       $28     !3, ->52
         39    > > FE_FETCH_R                                               $28, !6, ->52
   41    40    >   FETCH_DIM_R                                      ~29     !0, !6
         41        TYPE_CHECK                                  128          ~29
         42      > JMPZ                                                     ~30, ->51
   43    43    >   INIT_STATIC_METHOD_CALL                                  'recursion'
         44        FETCH_DIM_R                                      ~31     !0, !6
         45        SEND_VAL                                                 ~31
         46        DO_FCALL                                      0  $32     
         47        ASSIGN                                                   !7, $32
   44    48        UNSET_DIM                                                !0, !6
   45    49        ASSIGN_DIM                                               !0, !6
         50        OP_DATA                                                  !7
   39    51    > > JMP                                                      ->39
         52    >   FE_FREE                                                  $28
   50    53    > > RETURN                                                   !0
   51    54*     > RETURN                                                   null

End of function recursion

End of class RecursionImplementation.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.26 ms | 1404 KiB | 23 Q