3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array( 'root_trrreeee1' => array( 'path1' => array( 'description' => 'etc', 'child_of_path_1' => array( array('name' => '1'), array('name' => '1') ) ), 'path2' => array( 'description' => 'etc', 'child_of_path_2' => array( array('name' => '1'), array('name' => '2') ) ), ), 'name' => '1', 1 => array('name' => '1'), 'another_leaf' => '1' ); function array_value_path(array $array, $needle, &$path) { foreach($array as $key => $value) { if ($value == $needle || is_array($value) && array_value_path($value, $needle, $path)) { array_unshift($path, $key); return true; } } return false; } $path = []; array_value_path($a, ['name' => 1], $path); print_r($path);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mWjBO
function name:  (null)
number of ops:  11
compiled vars:  !0 = $a, !1 = $path
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   37     1        ASSIGN                                                   !1, <array>
   39     2        INIT_FCALL                                               'array_value_path'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 <array>
          5        SEND_REF                                                 !1
          6        DO_FCALL                                      0          
   41     7        INIT_FCALL                                               'print_r'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                                 
         10      > RETURN                                                   1

Function array_value_path:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 25
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 25
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 24
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 16
Branch analysis from position: 17
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/mWjBO
function name:  array_value_path
number of ops:  28
compiled vars:  !0 = $array, !1 = $needle, !2 = $path, !3 = $value, !4 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   27     3      > FE_RESET_R                                       $5      !0, ->25
          4    > > FE_FETCH_R                                       ~6      $5, !3, ->25
          5    >   ASSIGN                                                   !4, ~6
   28     6        IS_EQUAL                                         ~8      !3, !1
          7      > JMPNZ_EX                                         ~8      ~8, ->17
          8    >   TYPE_CHECK                                  128  ~9      !3
          9      > JMPZ_EX                                          ~9      ~9, ->16
         10    >   INIT_FCALL_BY_NAME                                       'array_value_path'
         11        SEND_VAR_EX                                              !3
         12        SEND_VAR_EX                                              !1
         13        SEND_VAR_EX                                              !2
         14        DO_FCALL                                      0  $10     
         15        BOOL                                             ~9      $10
         16    >   BOOL                                             ~8      ~9
         17    > > JMPZ                                                     ~8, ->24
   29    18    >   INIT_FCALL                                               'array_unshift'
         19        SEND_REF                                                 !2
         20        SEND_VAR                                                 !4
         21        DO_ICALL                                                 
   30    22        FE_FREE                                                  $5
         23      > RETURN                                                   <true>
   27    24    > > JMP                                                      ->4
         25    >   FE_FREE                                                  $5
   33    26      > RETURN                                                   <false>
   34    27*     > RETURN                                                   null

End of function array_value_path

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.2 ms | 1008 KiB | 16 Q