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 (isset($val['Parts'][0]['Body'])) { $body = $val['Parts'][0]['Body']; $ctype = $val['Parts'][0]['Headers']['content-type:']; break; } if (is_array($val) && isset($val['Parts'][0])) { 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/WDda0
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                                                 
   38     7      > RETURN                                                   1

Function getbody:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 28
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 28
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 27
Branch analysis from position: 23
Branch analysis from position: 28
Branch analysis from position: 28
filename:       /in/WDda0
function name:  getBody
number of ops:  33
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, ->28
          2    > > FE_FETCH_R                                       ~6      $5, !1, ->28
          3    >   ASSIGN                                                   !2, ~6
   27     4        FETCH_DIM_IS                                     ~8      !1, 'Parts'
          5        FETCH_DIM_IS                                     ~9      ~8, 0
          6        ISSET_ISEMPTY_DIM_OBJ                         0          ~9, 'Body'
          7      > JMPZ                                                     ~10, ->18
   28     8    >   FETCH_DIM_R                                      ~11     !1, 'Parts'
          9        FETCH_DIM_R                                      ~12     ~11, 0
         10        FETCH_DIM_R                                      ~13     ~12, 'Body'
         11        ASSIGN                                                   !3, ~13
   29    12        FETCH_DIM_R                                      ~15     !1, 'Parts'
         13        FETCH_DIM_R                                      ~16     ~15, 0
         14        FETCH_DIM_R                                      ~17     ~16, 'Headers'
         15        FETCH_DIM_R                                      ~18     ~17, 'content-type%3A'
         16        ASSIGN                                                   !4, ~18
   30    17      > JMP                                                      ->28
   32    18    >   TYPE_CHECK                                  128  ~20     !1
         19      > JMPZ_EX                                          ~20     ~20, ->23
         20    >   FETCH_DIM_IS                                     ~21     !1, 'Parts'
         21        ISSET_ISEMPTY_DIM_OBJ                         0  ~22     ~21, 0
         22        BOOL                                             ~20     ~22
         23    > > JMPZ                                                     ~20, ->27
   33    24    >   INIT_FCALL_BY_NAME                                       'getBody'
         25        SEND_VAR_EX                                              !1
         26        DO_FCALL                                      0          
   26    27    > > JMP                                                      ->2
         28    >   FE_FREE                                                  $5
   37    29        INIT_ARRAY                                       ~24     !3, 'body'
         30        ADD_ARRAY_ELEMENT                                ~24     !4, 'ctype'
         31      > RETURN                                                   ~24
   38    32*     > RETURN                                                   null

End of function getbody

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
201.03 ms | 1400 KiB | 15 Q