3v4l.org

run code in 300+ PHP versions simultaneously
<?php $payload = ['A', 'B', 'C', 'D']; $total = (1 << count($payload)) - 1; $result = []; for($i = 1; $i <= $total; ++$i){ if(($i & ($i - 1)) == 0) continue; // avoiding single items since you don't wish to have them $curr = []; for($j = 0; $j < count($payload); ++$j){ if(($i & (1 << $j)) > 0){ $curr[] = $payload[ $j ]; } } $result[] = $curr; } usort($result, function($a, $b){ return strcmp( implode("|", $a), implode("|", $b) ); }); print_r($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 8
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 8
Branch analysis from position: 32
Branch analysis from position: 8
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 16
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 8
Branch analysis from position: 32
Branch analysis from position: 8
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 23
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 27, Position 2 = 16
Branch analysis from position: 27
Branch analysis from position: 16
Branch analysis from position: 23
filename:       /in/jYsEi
function name:  (null)
number of ops:  41
compiled vars:  !0 = $payload, !1 = $total, !2 = $result, !3 = $i, !4 = $curr, !5 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        COUNT                                            ~7      !0
          2        SL                                               ~8      1, ~7
          3        SUB                                              ~9      ~8, 1
          4        ASSIGN                                                   !1, ~9
    7     5        ASSIGN                                                   !2, <array>
    9     6        ASSIGN                                                   !3, 1
          7      > JMP                                                      ->30
   10     8    >   SUB                                              ~13     !3, 1
          9        BW_AND                                           ~14     !3, ~13
         10        IS_EQUAL                                                 ~14, 0
         11      > JMPZ                                                     ~15, ->13
         12    > > JMP                                                      ->29
   11    13    >   ASSIGN                                                   !4, <array>
   12    14        ASSIGN                                                   !5, 0
         15      > JMP                                                      ->24
   13    16    >   SL                                               ~18     1, !5
         17        BW_AND                                           ~19     !3, ~18
         18        IS_SMALLER                                               0, ~19
         19      > JMPZ                                                     ~20, ->23
   14    20    >   FETCH_DIM_R                                      ~22     !0, !5
         21        ASSIGN_DIM                                               !4
         22        OP_DATA                                                  ~22
   12    23    >   PRE_INC                                                  !5
         24    >   COUNT                                            ~24     !0
         25        IS_SMALLER                                               !5, ~24
         26      > JMPNZ                                                    ~25, ->16
   17    27    >   ASSIGN_DIM                                               !2
         28        OP_DATA                                                  !4
    9    29    >   PRE_INC                                                  !3
         30    >   IS_SMALLER_OR_EQUAL                                      !3, !1
         31      > JMPNZ                                                    ~28, ->8
   20    32    >   INIT_FCALL                                               'usort'
         33        SEND_REF                                                 !2
         34        DECLARE_LAMBDA_FUNCTION                          ~29     [0]
   22    35        SEND_VAL                                                 ~29
   20    36        DO_ICALL                                                 
   24    37        INIT_FCALL                                               'print_r'
         38        SEND_VAR                                                 !2
         39        DO_ICALL                                                 
         40      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jYsEi
function name:  {closure}
number of ops:  16
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   21     2        INIT_FCALL                                               'strcmp'
          3        INIT_FCALL                                               'implode'
          4        SEND_VAL                                                 '%7C'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7        SEND_VAR                                                 $2
          8        INIT_FCALL                                               'implode'
          9        SEND_VAL                                                 '%7C'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $3      
         12        SEND_VAR                                                 $3
         13        DO_ICALL                                         $4      
         14      > RETURN                                                   $4
   22    15*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
139.72 ms | 1008 KiB | 17 Q