3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * I want it to go through the entire array, dropping down the nest until it reaches the array with index "Body" then return it * Why? Because I don't know how many times it will be nested */ $array = array(0 => array( "Headers" => array(), "Parts" => array( 0 => array( "Headers" => array("content-type:" => "CONTENT-TYPE"), "Parts" => array( 0 => array( "Headers" => array("content-type:" => "CONTENT-TYPE"), "Parts" => array( 0 => array( "Headers" => array("content-type:" => "CONTENT-TYPE"), "Parts" => array(), "Body" => "OMG BODY!!!!")))))))); var_dump( getBody($array) ); function getBody($array) { foreach ($array as $key => $val) { if ($key == 'Body') return $val; var_dump($val); if (is_array($val) && count($val)) { return getBody($val); } } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Sltvm
function name:  (null)
number of ops:  8
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   ASSIGN                                                   !0, <array>
   22     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL_BY_NAME                                       'getBody'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
   33     7      > RETURN                                                   1

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

End of function getbody

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.75 ms | 941 KiB | 16 Q