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-TYPE1"), "Parts" => array( 0 => array( "Headers" => array("content-type:" => "CONTENT-TYPE2"), "Parts" => array( 0 => array( "Headers" => array("content-type:" => "CONTENT-TYPE3"), "Parts" => array(), "Body" => "OMG BODY!!!!")))))))); var_dump( getBody($array) ); function getBody($array) { $cdr = array(); foreach ($array as $val) { if (is_array($val)) { if (isset($val['Body'])) { return $val['Body']; } $cdr = array_merge($cdr, $val); } } if ($cdr) { return getBody($cdr); } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PG6T9
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                                                 
   39     7      > RETURN                                                   1

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

End of function getbody

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.65 ms | 1400 KiB | 17 Q