3v4l.org

run code in 500+ PHP versions simultaneously
<?php function getAllCombinations(array $arr, int $n, array $selected = [], int $startIndex = 0): array { if (!$n) { return [array_merge($selected, [array_product($selected)])]; // generate payload } $result = []; $count = count($arr); for ($i = $startIndex; $i < $count; ++$i) { array_push( $result, ...getAllCombinations($arr, $n - 1, array_merge($selected, [$arr[$i]]), $i + 1) ); } return $result; } $primes = [2, 3, 5, 7, 11, 13, 17, 19, 23]; var_export(getAllCombinations($primes, 4));

Abusive script

This script was stopped while abusing our resources

Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Hau5L
function name:  (null)
number of ops:  9
compiled vars:  !0 = $primes
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   ASSIGN                                                       !0, <array>
   21     1        INIT_FCALL                                                   'var_export'
          2        INIT_FCALL                                                   'getallcombinations'
          3        SEND_VAR                                                     !0
          4        SEND_VAL                                                     4
          5        DO_FCALL                                          0  $2      
          6        SEND_VAR                                                     $2
          7        DO_ICALL                                                     
          8      > RETURN                                                       1

Function getallcombinations:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 17
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 22
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 22
Branch analysis from position: 44
Branch analysis from position: 22
filename:       /in/Hau5L
function name:  getAllCombinations
number of ops:  48
compiled vars:  !0 = $arr, !1 = $n, !2 = $selected, !3 = $startIndex, !4 = $result, !5 = $count, !6 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV_INIT                                            !2      <array>
          3        RECV_INIT                                            !3      0
    5     4        BOOL_NOT                                             ~7      !1
          5      > JMPZ                                                         ~7, ->17
    6     6    >   INIT_FCALL                                                   'array_merge'
          7        SEND_VAR                                                     !2
          8        INIT_FCALL                                                   'array_product'
          9        SEND_VAR                                                     !2
         10        DO_ICALL                                             $8      
         11        INIT_ARRAY                                           ~9      $8
         12        SEND_VAL                                                     ~9
         13        DO_ICALL                                             $10     
         14        INIT_ARRAY                                           ~11     $10
         15        VERIFY_RETURN_TYPE                                           ~11
         16      > RETURN                                                       ~11
    9    17    >   ASSIGN                                                       !4, <array>
   10    18        COUNT                                                ~13     !0
         19        ASSIGN                                                       !5, ~13
   11    20        ASSIGN                                                       !6, !3
         21      > JMP                                                          ->42
   12    22    >   INIT_FCALL                                                   'array_push'
   13    23        SEND_REF                                                     !4
   14    24        INIT_FCALL_BY_NAME                                           'getAllCombinations'
         25        SEND_VAR_EX                                                  !0
         26        SUB                                                  ~16     !1, 1
         27        SEND_VAL_EX                                                  ~16
         28        INIT_FCALL                                                   'array_merge'
         29        SEND_VAR                                                     !2
         30        FETCH_DIM_R                                          ~17     !0, !6
         31        INIT_ARRAY                                           ~18     ~17
         32        SEND_VAL                                                     ~18
         33        DO_ICALL                                             $19     
         34        SEND_VAR_NO_REF_EX                                           $19
         35        ADD                                                  ~20     !6, 1
         36        SEND_VAL_EX                                                  ~20
         37        DO_FCALL                                          0  $21     
         38        SEND_UNPACK                                                  $21
         39        CHECK_UNDEF_ARGS                                             
   12    40        DO_ICALL                                                     
   11    41        PRE_INC                                                      !6
         42    >   IS_SMALLER                                                   !6, !5
         43      > JMPNZ                                                        ~24, ->22
   17    44    >   VERIFY_RETURN_TYPE                                           !4
         45      > RETURN                                                       !4
   18    46*       VERIFY_RETURN_TYPE                                           
         47*     > RETURN                                                       null

End of function getallcombinations

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
169.48 ms | 2337 KiB | 18 Q