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); } } return $combinations; } $traits = array ( array('Happy', 'Sad', 'Angry', 'Hopeful'), array('Outgoing', 'Introverted'), array('Tall', 'Short', 'Medium'), array('Handsome', 'Plain', 'Ugly') ); $combinations = getCombinations($traits); // As a string echo $combinations; // As an array $combinationsArray = explode("\n",$combinations); print_r($combinationsArray);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/poTS8
function name:  (null)
number of ops:  15
compiled vars:  !0 = $traits, !1 = $combinations, !2 = $combinationsArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, <array>
   24     1        INIT_FCALL                                               'getcombinations'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $4      
          4        ASSIGN                                                   !1, $4
   27     5        ECHO                                                     !1
   30     6        INIT_FCALL                                               'explode'
          7        SEND_VAL                                                 '%0A'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $6      
         10        ASSIGN                                                   !2, $6
   31    11        INIT_FCALL                                               'print_r'
         12        SEND_VAR                                                 !2
         13        DO_ICALL                                                 
         14      > 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
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/poTS8
function name:  getCombinations
number of ops:  30
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      > RETURN                                                   !3
   14    29*     > RETURN                                                   null

End of function getcombinations

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.88 ms | 1403 KiB | 20 Q