3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ '1' => true, ['2' => false, '4' => true], '3' => true ]; function findKeysWithTrueValues(array $array): array { $matches = []; foreach ($array as $key => $value) { if (is_array($value)) { foreach (findKeysWithTrueValues($value) as $match) { $matches[] = $match; } } elseif ($value === true) { $matches[] = $key; } } return $matches; } print_r(findKeysWithTrueValues($array));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/42tX2
function name:  (null)
number of ops:  8
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   24     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'findkeyswithtruevalues'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

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

End of function findkeyswithtruevalues

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.1 ms | 1007 KiB | 15 Q