3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = json_decode('{ "name": "", "type": "layout", "children": [ { "name": "", "type": "section", "children": [ { "name": "", "type": "row", "children": [ { "name": "", "type": "column", "props": { }, "children": [] }, { "type": "column", "children": [ { "type": "itemdata", "props": { "basevalue": "100" }, "children": [] } ] } ] } ] }]}',true); //print_r($arr); function getBaseValue($arr,$search_key){ $pending_calls = []; foreach($arr as $key => $value){ if(is_array($value)){ $pending_calls[] = $value; }else if($search_key === $key){ return $value; } } foreach($pending_calls as $call){ $returned_val = getBaseValue($call,$search_key); if($returned_val !== false) return $returned_val; } return false; } echo getBaseValue($arr,'basevalue');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gdLK1
function name:  (null)
number of ops:  11
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'json_decode'
          1        SEND_VAL                                                 '%7B%0A++%22name%22%3A+%22%22%2C%0A++%22type%22%3A+%22layout%22%2C%0A++%22children%22%3A+%5B%0A++++%7B%0A++++++%22name%22%3A+%22%22%2C%0A++++++%22type%22%3A+%22section%22%2C%0A%0A++++++%22children%22%3A+%5B%0A++++++++%7B%0A++++++++++%22name%22%3A+%22%22%2C%0A++++++++++%22type%22%3A+%22row%22%2C%0A++++++++++%22children%22%3A+%5B%0A++++++++++++%7B%0A++++++++++++++%22name%22%3A+%22%22%2C%0A++++++++++++++%22type%22%3A+%22column%22%2C%0A++++++++++++++%22props%22%3A+%7B%0A%0A++++++++++++++%7D%2C%0A++++++++++++++%22children%22%3A+%5B%5D%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A++++++++++++++%22type%22%3A+%22column%22%2C%0A++++++++++++++%22children%22%3A+%5B%0A++++++++++++++++%7B%0A++++++++++++++++++%22type%22%3A+%22itemdata%22%2C%0A++++++++++++++++++%22props%22%3A+%7B%0A++++++++++++++++++++%22basevalue%22%3A+%22100%22%0A++++++++++++++++++%7D%2C%0A++++++++++++++++++%22children%22%3A+%5B%5D%0A++++++++++++++++%7D+++++++++++++%0A%0A++++++++++%5D%0A++++++++%7D%0A++++++%5D%0A++++%7D%0A++%5D%0A%7D%5D%7D'
   40     2        SEND_VAL                                                 <true>
    3     3        DO_ICALL                                         $1      
          4        ASSIGN                                                   !0, $1
   64     5        INIT_FCALL                                               'getbasevalue'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 'basevalue'
          8        DO_FCALL                                      0  $3      
          9        ECHO                                                     $3
         10      > RETURN                                                   1

Function getbasevalue:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 11
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 16
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 29
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 29
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 28
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
Branch analysis from position: 16
filename:       /in/gdLK1
function name:  getBaseValue
number of ops:  32
compiled vars:  !0 = $arr, !1 = $search_key, !2 = $pending_calls, !3 = $value, !4 = $key, !5 = $call, !6 = $returned_val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   46     2        ASSIGN                                                   !2, <array>
   47     3      > FE_RESET_R                                       $8      !0, ->16
          4    > > FE_FETCH_R                                       ~9      $8, !3, ->16
          5    >   ASSIGN                                                   !4, ~9
   48     6        TYPE_CHECK                                  128          !3
          7      > JMPZ                                                     ~11, ->11
   49     8    >   ASSIGN_DIM                                               !2
          9        OP_DATA                                                  !3
   48    10      > JMP                                                      ->15
   50    11    >   IS_IDENTICAL                                             !1, !4
         12      > JMPZ                                                     ~13, ->15
   51    13    >   FE_FREE                                                  $8
         14      > RETURN                                                   !3
   47    15    > > JMP                                                      ->4
         16    >   FE_FREE                                                  $8
   55    17      > FE_RESET_R                                       $14     !2, ->29
         18    > > FE_FETCH_R                                               $14, !5, ->29
   56    19    >   INIT_FCALL_BY_NAME                                       'getBaseValue'
         20        SEND_VAR_EX                                              !5
         21        SEND_VAR_EX                                              !1
         22        DO_FCALL                                      0  $15     
         23        ASSIGN                                                   !6, $15
   57    24        TYPE_CHECK                                  1018          !6
         25      > JMPZ                                                     ~17, ->28
         26    >   FE_FREE                                                  $14
         27      > RETURN                                                   !6
   55    28    > > JMP                                                      ->18
         29    >   FE_FREE                                                  $14
   60    30      > RETURN                                                   <false>
   61    31*     > RETURN                                                   null

End of function getbasevalue

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.36 ms | 1005 KiB | 15 Q