3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getCombinations($traits, $string = '', $i = 0) { $combinations = ''; if ($i >= count($traits)) return trim($string) . "\n"; else { foreach ($traits[$i] as $trait) { $combinations .= getCombinations($traits, "$string $trait", $i + 1); } } if($i==0) return explode("\n",$combinations); return $combinations; } $traits = array ( array('Happy', 'Sad', 'Angry', 'Hopeful'), array('Outgoing', 'Introverted'), array('Tall', 'Short', 'Medium'), array('Handsome', 'Plain', 'Ugly') ); $combinations = getCombinations($traits); print_r($combinations);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/X3i3p
function name:  (null)
number of ops:  9
compiled vars:  !0 = $traits, !1 = $combinations
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                   !0, <array>
   25     1        INIT_FCALL                                               'getcombinations'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   27     5        INIT_FCALL                                               'print_r'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function getcombinations:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 13
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 27
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 27
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 35
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/X3i3p
function name:  getCombinations
number of ops:  37
compiled vars:  !0 = $traits, !1 = $string, !2 = $i, !3 = $combinations, !4 = $trait
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      ''
          2        RECV_INIT                                        !2      0
    4     3        ASSIGN                                                   !3, ''
    5     4        COUNT                                            ~6      !0
          5        IS_SMALLER_OR_EQUAL                                      ~6, !2
          6      > JMPZ                                                     ~7, ->13
    6     7    >   INIT_FCALL                                               'trim'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $8      
         10        CONCAT                                           ~9      $8, '%0A'
         11      > RETURN                                                   ~9
         12*       JMP                                                      ->28
    9    13    >   FETCH_DIM_R                                      ~10     !0, !2
         14      > FE_RESET_R                                       $11     ~10, ->27
         15    > > FE_FETCH_R                                               $11, !4, ->27
   10    16    >   INIT_FCALL_BY_NAME                                       'getCombinations'
         17        SEND_VAR_EX                                              !0
         18        ROPE_INIT                                     3  ~13     !1
         19        ROPE_ADD                                      1  ~13     ~13, '+'
         20        ROPE_END                                      2  ~12     ~13, !4
         21        SEND_VAL_EX                                              ~12
         22        ADD                                              ~15     !2, 1
         23        SEND_VAL_EX                                              ~15
         24        DO_FCALL                                      0  $16     
         25        ASSIGN_OP                                     8          !3, $16
    9    26      > JMP                                                      ->15
         27    >   FE_FREE                                                  $11
   13    28        IS_EQUAL                                                 !2, 0
         29      > JMPZ                                                     ~18, ->35
         30    >   INIT_FCALL                                               'explode'
         31        SEND_VAL                                                 '%0A'
         32        SEND_VAR                                                 !3
         33        DO_ICALL                                         $19     
         34      > RETURN                                                   $19
   14    35    > > RETURN                                                   !3
   15    36*     > RETURN                                                   null

End of function getcombinations

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.14 ms | 1403 KiB | 20 Q