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; if (is_array($val)) { return getBody($val); } } return array("body" => $body, "ctype" => $ctype); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/d3ZhD
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                                                 
   34     7      > RETURN                                                   1

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

End of function getbody

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.3 ms | 1396 KiB | 15 Q