3v4l.org

run code in 500+ PHP versions simultaneously
<?php function permStacker($array,$length){ $stack=[[]]; // declare intitial empty element for($x=0; $x<$length; ++$x){ // limit the total number of passes / max string length foreach($stack as $combination){ foreach(array_diff($array,range('a',end($combination))) as $left){ // do not include iterate letter that come earlier than rightmost letter $merge=array_merge($combination,[$left]); $stack[implode($merge)]=$merge; // keys hold desired strings, values hold subarray of combinations for iterated referencing } } } unset($stack[0]); // remove initial empty element return array_keys($stack); // return array of permutations as space delimited strings } $permutations=permStacker(range('a','h'),4); echo 'Total Permutations: ',sizeof($permutations),"\n"; var_export($permutations);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eW4A6
function name:  (null)
number of ops:  17
compiled vars:  !0 = $permutations
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   INIT_FCALL                                                   'permstacker'
          1        INIT_FCALL                                                   'range'
          2        SEND_VAL                                                     'a'
          3        SEND_VAL                                                     'h'
          4        DO_ICALL                                             $1      
          5        SEND_VAR                                                     $1
          6        SEND_VAL                                                     4
          7        DO_FCALL                                          0  $2      
          8        ASSIGN                                                       !0, $2
   18     9        ECHO                                                         'Total+Permutations%3A+'
         10        COUNT                                                ~4      !0
         11        ECHO                                                         ~4
         12        ECHO                                                         '%0A'
   19    13        INIT_FCALL                                                   'var_export'
         14        SEND_VAR                                                     !0
         15        DO_ICALL                                                     
         16      > RETURN                                                       1

Function permstacker:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 5
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 32
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 32
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 30
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 30
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 30
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 5
Branch analysis from position: 36
Branch analysis from position: 5
Branch analysis from position: 32
filename:       /in/eW4A6
function name:  permStacker
number of ops:  42
compiled vars:  !0 = $array, !1 = $length, !2 = $stack, !3 = $x, !4 = $combination, !5 = $left, !6 = $merge
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    3     2        ASSIGN                                                       !2, <array>
    4     3        ASSIGN                                                       !3, 0
          4      > JMP                                                          ->34
    5     5    > > FE_RESET_R                                           $9      !2, ->32
          6    > > FE_FETCH_R                                                   $9, !4, ->32
    6     7    >   INIT_FCALL                                                   'array_diff'
          8        SEND_VAR                                                     !0
          9        INIT_FCALL                                                   'range'
         10        SEND_VAL                                                     'a'
         11        INIT_FCALL                                                   'end'
         12        SEND_REF                                                     !4
         13        DO_ICALL                                             $10     
         14        SEND_VAR                                                     $10
         15        DO_ICALL                                             $11     
         16        SEND_VAR                                                     $11
         17        DO_ICALL                                             $12     
         18      > FE_RESET_R                                           $13     $12, ->30
         19    > > FE_FETCH_R                                                   $13, !5, ->30
    7    20    >   INIT_FCALL                                                   'array_merge'
         21        SEND_VAR                                                     !4
         22        INIT_ARRAY                                           ~14     !5
         23        SEND_VAL                                                     ~14
         24        DO_ICALL                                             $15     
         25        ASSIGN                                                       !6, $15
    8    26        FRAMELESS_ICALL_1                implode             ~17     !6
         27        ASSIGN_DIM                                                   !2, ~17
         28        OP_DATA                                                      !6
    6    29      > JMP                                                          ->19
         30    >   FE_FREE                                                      $13
    5    31      > JMP                                                          ->6
         32    >   FE_FREE                                                      $9
    4    33        PRE_INC                                                      !3
         34    >   IS_SMALLER                                                   !3, !1
         35      > JMPNZ                                                        ~20, ->5
   12    36    >   UNSET_DIM                                                    !2, 0
   13    37        INIT_FCALL                                                   'array_keys'
         38        SEND_VAR                                                     !2
         39        DO_ICALL                                             $21     
         40      > RETURN                                                       $21
   14    41*     > RETURN                                                       null

End of function permstacker

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
174.59 ms | 3685 KiB | 20 Q