3v4l.org

run code in 300+ PHP versions simultaneously
<?php // function to generate and print all N! permutations of $str. (N = strlen($str)). function permute($str,$i,$n,$len) { global $ret; if ($i == $n){ if(in_array(substr($str,0,$len),$ret)==false){$ret[]=substr($str,0,$len);} }else { for ($j = $i; $j < $n; $j++) { swap($str,$i,$j); permute($str, $i+1, $n, $len); swap($str,$i,$j); // backtrack. } } } // function to swap the char at pos $i and $j of $str. function swap(&$str,$i,$j) { $temp = $str[$i]; $str[$i] = $str[$j]; $str[$j] = $temp; } $ret = array(); $str = "123456"; permute($str,0,strlen($str), 3); // call the function. ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aNF9o
function name:  (null)
number of ops:  10
compiled vars:  !0 = $ret, !1 = $str
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                   !0, <array>
   24     1        ASSIGN                                                   !1, '123456'
   25     2        INIT_FCALL                                               'permute'
          3        SEND_VAR                                                 !1
          4        SEND_VAL                                                 0
          5        STRLEN                                           ~4      !1
          6        SEND_VAL                                                 ~4
          7        SEND_VAL                                                 3
          8        DO_FCALL                                      0          
   26     9      > RETURN                                                   1

Function permute:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 26
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 25
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 28
Branch analysis from position: 48
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 48, Position 2 = 28
Branch analysis from position: 48
Branch analysis from position: 28
filename:       /in/aNF9o
function name:  permute
number of ops:  49
compiled vars:  !0 = $str, !1 = $i, !2 = $n, !3 = $len, !4 = $ret, !5 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    5     4        BIND_GLOBAL                                              !4, 'ret'
    6     5        IS_EQUAL                                                 !1, !2
          6      > JMPZ                                                     ~6, ->26
    7     7    >   INIT_FCALL                                               'in_array'
          8        INIT_FCALL                                               'substr'
          9        SEND_VAR                                                 !0
         10        SEND_VAL                                                 0
         11        SEND_VAR                                                 !3
         12        DO_ICALL                                         $7      
         13        SEND_VAR                                                 $7
         14        SEND_VAR                                                 !4
         15        DO_ICALL                                         $8      
         16        BOOL_NOT                                         ~9      $8
         17      > JMPZ                                                     ~9, ->25
         18    >   INIT_FCALL                                               'substr'
         19        SEND_VAR                                                 !0
         20        SEND_VAL                                                 0
         21        SEND_VAR                                                 !3
         22        DO_ICALL                                         $11     
         23        ASSIGN_DIM                                               !4
         24        OP_DATA                                                  $11
         25    > > JMP                                                      ->48
    9    26    >   ASSIGN                                                   !5, !1
         27      > JMP                                                      ->46
   10    28    >   INIT_FCALL_BY_NAME                                       'swap'
         29        SEND_VAR_EX                                              !0
         30        SEND_VAR_EX                                              !1
         31        SEND_VAR_EX                                              !5
         32        DO_FCALL                                      0          
   11    33        INIT_FCALL_BY_NAME                                       'permute'
         34        SEND_VAR_EX                                              !0
         35        ADD                                              ~14     !1, 1
         36        SEND_VAL_EX                                              ~14
         37        SEND_VAR_EX                                              !2
         38        SEND_VAR_EX                                              !3
         39        DO_FCALL                                      0          
   12    40        INIT_FCALL_BY_NAME                                       'swap'
         41        SEND_VAR_EX                                              !0
         42        SEND_VAR_EX                                              !1
         43        SEND_VAR_EX                                              !5
         44        DO_FCALL                                      0          
    9    45        PRE_INC                                                  !5
         46    >   IS_SMALLER                                               !5, !2
         47      > JMPNZ                                                    ~18, ->28
   15    48    > > RETURN                                                   null

End of function permute

Function swap:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aNF9o
function name:  swap
number of ops:  11
compiled vars:  !0 = $str, !1 = $i, !2 = $j, !3 = $temp
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   19     3        FETCH_DIM_R                                      ~4      !0, !1
          4        ASSIGN                                                   !3, ~4
   20     5        FETCH_DIM_R                                      ~7      !0, !2
          6        ASSIGN_DIM                                               !0, !1
          7        OP_DATA                                                  ~7
   21     8        ASSIGN_DIM                                               !0, !2
          9        OP_DATA                                                  !3
   22    10      > RETURN                                                   null

End of function swap

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.59 ms | 1403 KiB | 18 Q