3v4l.org

run code in 300+ 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 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 5
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 34
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 34
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 32
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 32
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 32
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 38, Position 2 = 5
Branch analysis from position: 38
Branch analysis from position: 5
Branch analysis from position: 34
filename:       /in/eW4A6
function name:  permStacker
number of ops:  44
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                                                      ->36
    5     5    > > FE_RESET_R                                       $9      !2, ->34
          6    > > FE_FETCH_R                                               $9, !4, ->34
    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, ->32
         19    > > FE_FETCH_R                                               $13, !5, ->32
    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        INIT_FCALL                                               'implode'
         27        SEND_VAR                                                 !6
         28        DO_ICALL                                         $17     
         29        ASSIGN_DIM                                               !2, $17
         30        OP_DATA                                                  !6
    6    31      > JMP                                                      ->19
         32    >   FE_FREE                                                  $13
    5    33      > JMP                                                      ->6
         34    >   FE_FREE                                                  $9
    4    35        PRE_INC                                                  !3
         36    >   IS_SMALLER                                               !3, !1
         37      > JMPNZ                                                    ~20, ->5
   12    38    >   UNSET_DIM                                                !2, 0
   13    39        INIT_FCALL                                               'array_keys'
         40        SEND_VAR                                                 !2
         41        DO_ICALL                                         $21     
         42      > RETURN                                                   $21
   14    43*     > RETURN                                                   null

End of function permstacker

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.35 ms | 1016 KiB | 21 Q