3v4l.org

run code in 300+ PHP versions simultaneously
<?php $testarr = array ( 'advertiser' => array ( 'id' => 135234, 'name' => 'Some Advertiser', 'agency' => array ( 'id' => 137734, 'name' => 'Some Agenecy', 'organisation' => array ( 'id' => 383734, 'name' => 'Some Organisation' ), ) ) ); function getkeypath($arr, $lookup) { if (in_array($lookup, $arr)) { return array($lookup); } else { foreach ($arr as $key => $subarr) { if (is_array($subarr)) { $ret = getkeypath($subarr, $lookup); if ($ret) { $ret[] = $key; return $ret; } } } } return null; } echo '$testarr: ' . "/n"; print_r($testarr); echo '<br>' . 'Organisation: ' . '<br>' . print_r(getkeypath($testarr, '383734'), true) . '<br>';
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/b1mkO
function name:  (null)
number of ops:  17
compiled vars:  !0 = $testarr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   50     1        ECHO                                                     '%24testarr%3A+%2Fn'
   51     2        INIT_FCALL                                               'print_r'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
   52     5        INIT_FCALL                                               'print_r'
          6        INIT_FCALL                                               'getkeypath'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 '383734'
          9        DO_FCALL                                      0  $3      
         10        SEND_VAR                                                 $3
         11        SEND_VAL                                                 <true>
         12        DO_ICALL                                         $4      
         13        CONCAT                                           ~5      '%3Cbr%3EOrganisation%3A+%3Cbr%3E', $4
         14        CONCAT                                           ~6      ~5, '%3Cbr%3E'
         15        ECHO                                                     ~6
         16      > RETURN                                                   1

Function getkeypath:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 10
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 26
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 26
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 25
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 25
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/b1mkO
function name:  getkeypath
number of ops:  29
compiled vars:  !0 = $arr, !1 = $lookup, !2 = $subarr, !3 = $key, !4 = $ret
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   26     2        INIT_FCALL                                               'in_array'
          3        SEND_VAR                                                 !1
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $5      
          6      > JMPZ                                                     $5, ->10
   28     7    >   INIT_ARRAY                                       ~6      !1
          8      > RETURN                                                   ~6
          9*       JMP                                                      ->27
   32    10    > > FE_RESET_R                                       $7      !0, ->26
         11    > > FE_FETCH_R                                       ~8      $7, !2, ->26
         12    >   ASSIGN                                                   !3, ~8
   34    13        TYPE_CHECK                                  128          !2
         14      > JMPZ                                                     ~10, ->25
   36    15    >   INIT_FCALL_BY_NAME                                       'getkeypath'
         16        SEND_VAR_EX                                              !2
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0  $11     
         19        ASSIGN                                                   !4, $11
   38    20      > JMPZ                                                     !4, ->25
   40    21    >   ASSIGN_DIM                                               !4
         22        OP_DATA                                                  !3
   41    23        FE_FREE                                                  $7
         24      > RETURN                                                   !4
   32    25    > > JMP                                                      ->11
         26    >   FE_FREE                                                  $7
   47    27      > RETURN                                                   null
   48    28*     > RETURN                                                   null

End of function getkeypath

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
181.51 ms | 1403 KiB | 18 Q