3v4l.org

run code in 300+ PHP versions simultaneously
<?php $people = [ [ "sponsor" => "Zack", "referal" => "Joey", "status" => 1, ], [ "sponsor" => "Joey", "referal" => "Tracy", "status" => 0, ], [ "sponsor" => "Tracy", "referal" => "Helen", "status" => 0, ], [ "sponsor" => "Helen", "referal" => "Richard", "status" => 0, ], [ "sponsor" => "Felipe", "referal" => "Juan", "status" => 0, ], [ "sponsor" => "Richard", "referal" => "Mike", "status" => 0, ], ]; static $i = 0; function getParentSponsor($referal, $people) { foreach ($people as $pair) { if ($pair["referal"] === $referal) { if ($pair["status"] === 1) { return $pair["sponsor"]; } else { return getParentSponsor($pair["sponsor"], $people); } return $pair["sponsor"]; } } $i++; } echo getParentSponsor("Mike", array_reverse($people));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/0dkOJ
function name:  (null)
number of ops:  11
compiled vars:  !0 = $people, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   35     1        BIND_STATIC                                              !1
   50     2        INIT_FCALL                                               'getparentsponsor'
          3        SEND_VAL                                                 'Mike'
          4        INIT_FCALL                                               'array_reverse'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        SEND_VAR                                                 $3
          8        DO_FCALL                                      0  $4      
          9        ECHO                                                     $4
         10      > RETURN                                                   1

Function getparentsponsor:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 26
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 26
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 25
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/0dkOJ
function name:  getParentSponsor
number of ops:  29
compiled vars:  !0 = $referal, !1 = $people, !2 = $pair, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   37     2      > FE_RESET_R                                       $4      !1, ->26
          3    > > FE_FETCH_R                                               $4, !2, ->26
   38     4    >   FETCH_DIM_R                                      ~5      !2, 'referal'
          5        IS_IDENTICAL                                             !0, ~5
          6      > JMPZ                                                     ~6, ->25
   39     7    >   FETCH_DIM_R                                      ~7      !2, 'status'
          8        IS_IDENTICAL                                             ~7, 1
          9      > JMPZ                                                     ~8, ->14
   40    10    >   FETCH_DIM_R                                      ~9      !2, 'sponsor'
         11        FE_FREE                                                  $4
         12      > RETURN                                                   ~9
         13*       JMP                                                      ->22
   43    14    >   INIT_FCALL_BY_NAME                                       'getParentSponsor'
         15        CHECK_FUNC_ARG                                           
         16        FETCH_DIM_FUNC_ARG                               $10     !2, 'sponsor'
         17        SEND_FUNC_ARG                                            $10
         18        SEND_VAR_EX                                              !1
         19        DO_FCALL                                      0  $11     
         20        FE_FREE                                                  $4
         21      > RETURN                                                   $11
   45    22*       FETCH_DIM_R                                      ~12     !2, 'sponsor'
         23*       FE_FREE                                                  $4
         24*       RETURN                                                   ~12
   37    25    > > JMP                                                      ->3
         26    >   FE_FREE                                                  $4
   48    27        PRE_INC                                                  !3
   49    28      > RETURN                                                   null

End of function getparentsponsor

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
132.79 ms | 1407 KiB | 16 Q