3v4l.org

run code in 300+ PHP versions simultaneously
<?php function permutations($set) { $solutions=array(); $n=count($set); $p=array_keys($set); $i=1; while ($i<$n) { if ($p[$i]>0) { $p[$i]--; $j=0; if ($i%2==1) $j=$p[$i]; //swap $tmp=$set[$j]; $set[$j]=$set[$i]; $set[$i]=$tmp; $i=1; $solutions[]=$set; } elseif ($p[$i]==0) { $p[$i]=$i; $i++; } } return $solutions; } $set=array("x1", "x2", "x3"); print_r(permutations($set));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/IUtWN
function name:  (null)
number of ops:  8
compiled vars:  !0 = $set
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   ASSIGN                                                   !0, <array>
   34     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'permutations'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function permutations:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 10
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 32
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 21
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 10
Branch analysis from position: 40
Branch analysis from position: 10
Branch analysis from position: 38
filename:       /in/IUtWN
function name:  permutations
number of ops:  42
compiled vars:  !0 = $set, !1 = $solutions, !2 = $n, !3 = $p, !4 = $i, !5 = $j, !6 = $tmp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    4     1        ASSIGN                                                   !1, <array>
    5     2        COUNT                                            ~8      !0
          3        ASSIGN                                                   !2, ~8
    6     4        INIT_FCALL                                               'array_keys'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !3, $10
    7     8        ASSIGN                                                   !4, 1
    9     9      > JMP                                                      ->38
   11    10    >   FETCH_DIM_R                                      ~13     !3, !4
         11        IS_SMALLER                                               0, ~13
         12      > JMPZ                                                     ~14, ->32
   13    13    >   FETCH_DIM_RW                                     $15     !3, !4
         14        PRE_DEC                                                  $15
   14    15        ASSIGN                                                   !5, 0
   15    16        MOD                                              ~18     !4, 2
         17        IS_EQUAL                                                 ~18, 1
         18      > JMPZ                                                     ~19, ->21
   16    19    >   FETCH_DIM_R                                      ~20     !3, !4
         20        ASSIGN                                                   !5, ~20
   18    21    >   FETCH_DIM_R                                      ~22     !0, !5
         22        ASSIGN                                                   !6, ~22
   19    23        FETCH_DIM_R                                      ~25     !0, !4
         24        ASSIGN_DIM                                               !0, !5
         25        OP_DATA                                                  ~25
   20    26        ASSIGN_DIM                                               !0, !4
         27        OP_DATA                                                  !6
   21    28        ASSIGN                                                   !4, 1
   22    29        ASSIGN_DIM                                               !1
         30        OP_DATA                                                  !0
         31      > JMP                                                      ->38
   24    32    >   FETCH_DIM_R                                      ~29     !3, !4
         33        IS_EQUAL                                                 ~29, 0
         34      > JMPZ                                                     ~30, ->38
   26    35    >   ASSIGN_DIM                                               !3, !4
         36        OP_DATA                                                  !4
   27    37        PRE_INC                                                  !4
    9    38    >   IS_SMALLER                                               !4, !2
         39      > JMPNZ                                                    ~33, ->10
   30    40    > > RETURN                                                   !1
   31    41*     > RETURN                                                   null

End of function permutations

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
147.65 ms | 1403 KiB | 18 Q