3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isItEnd($array){ return !array_key_exists('ancestors', $array); } function getThirdFromEnd($category){ if(!isItEnd($category)){ $away_from_parent = getThirdFromEnd($category['ancestors']['BrowseNode']); if($away_from_parent == 0){ $away_from_parent = $category['ancestors']['BrowseNode']; } else { $away_from_parent--; } } else { $away_from_parent = 2; } return $away_from_parent; } $category = array( "BrowseNodeId" => "11256", "name"=> "Folklore & Mythology", "ancestors" => array( "BrowseNode" => array( "BrowseNodeId" => "11232", "name"=> "Social Sciences", "ancestors" => array( "BrowseNode" => array( "BrowseNodeId" => "3377866011", "name"=> "Politics & Social Sciences", "ancestors" => array( "BrowseNode" => array( "BrowseNodeId" => "1000", "name"=> "Subjects", "IsCategoryRoot" => true, "ancestors" => array( "BrowseNode" => array( "BrowseNodeId" => "283155", "name"=> "Books", ), ), ), ), ), ), ), ), ); $cat = getThirdFromEnd($category); echo "<pre>" . print_r($cat, 1) . "</pre>";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SeKvM
function name:  (null)
number of ops:  13
compiled vars:  !0 = $category, !1 = $cat
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, <array>
   51     1        INIT_FCALL                                               'getthirdfromend'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   52     5        INIT_FCALL                                               'print_r'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 1
          8        DO_ICALL                                         $5      
          9        CONCAT                                           ~6      '%3Cpre%3E', $5
         10        CONCAT                                           ~7      ~6, '%3C%2Fpre%3E'
         11        ECHO                                                     ~7
         12      > RETURN                                                   1

Function isitend:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SeKvM
function name:  isItEnd
number of ops:  5
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    4     1        ARRAY_KEY_EXISTS                                 ~1      'ancestors', !0
          2        BOOL_NOT                                         ~2      ~1
          3      > RETURN                                                   ~2
    5     4*     > RETURN                                                   null

End of function isitend

Function getthirdfromend:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 21
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
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 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/SeKvM
function name:  getThirdFromEnd
number of ops:  24
compiled vars:  !0 = $category, !1 = $away_from_parent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    8     1        INIT_FCALL                                               'isitend'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        BOOL_NOT                                         ~3      $2
          5      > JMPZ                                                     ~3, ->21
    9     6    >   INIT_FCALL_BY_NAME                                       'getThirdFromEnd'
          7        CHECK_FUNC_ARG                                           
          8        FETCH_DIM_FUNC_ARG                               $4      !0, 'ancestors'
          9        FETCH_DIM_FUNC_ARG                               $5      $4, 'BrowseNode'
         10        SEND_FUNC_ARG                                            $5
         11        DO_FCALL                                      0  $6      
         12        ASSIGN                                                   !1, $6
   10    13        IS_EQUAL                                                 !1, 0
         14      > JMPZ                                                     ~8, ->19
   11    15    >   FETCH_DIM_R                                      ~9      !0, 'ancestors'
         16        FETCH_DIM_R                                      ~10     ~9, 'BrowseNode'
         17        ASSIGN                                                   !1, ~10
         18      > JMP                                                      ->20
   13    19    >   PRE_DEC                                                  !1
         20    > > JMP                                                      ->22
   16    21    >   ASSIGN                                                   !1, 2
   18    22    > > RETURN                                                   !1
   19    23*     > RETURN                                                   null

End of function getthirdfromend

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
126.78 ms | 1407 KiB | 17 Q