3v4l.org

run code in 300+ PHP versions simultaneously
<?php function permuteUnique($items, $perms = [], &$return = []) { if (empty($items)) { $return[] = $perms; } else { sort($items); $prev = false; for ($i = count($items) - 1; $i >= 0; --$i) { $newitems = $items; $tmp = array_splice($newitems, $i, 1)[0]; if ($tmp != $prev) { $prev = $tmp; $newperms = $perms; array_unshift($newperms, $tmp); permuteUnique($newitems, $newperms, $return); } } return $return; } } $permutations = permuteUnique(["x1", "x2", "x3"]); var_dump($permutations);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/RLS36
function name:  (null)
number of ops:  8
compiled vars:  !0 = $permutations
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                               'permuteunique'
          1        SEND_VAL                                                 <array>
          2        DO_FCALL                                      0  $1      
          3        ASSIGN                                                   !0, $1
   23     4        INIT_FCALL                                               'var_dump'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function permuteunique:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 16
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 37
Branch analysis from position: 26
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 16
Branch analysis from position: 40
Branch analysis from position: 16
Branch analysis from position: 37
filename:       /in/RLS36
function name:  permuteUnique
number of ops:  42
compiled vars:  !0 = $items, !1 = $perms, !2 = $return, !3 = $prev, !4 = $i, !5 = $newitems, !6 = $tmp, !7 = $newperms
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <array>
          2        RECV_INIT                                        !2      <array>
    3     3        ISSET_ISEMPTY_CV                                         !0
          4      > JMPZ                                                     ~8, ->8
    4     5    >   ASSIGN_DIM                                               !2
          6        OP_DATA                                                  !1
          7      > JMP                                                      ->41
    6     8    >   INIT_FCALL                                               'sort'
          9        SEND_REF                                                 !0
         10        DO_ICALL                                                 
    7    11        ASSIGN                                                   !3, <false>
    8    12        COUNT                                            ~12     !0
         13        SUB                                              ~13     ~12, 1
         14        ASSIGN                                                   !4, ~13
         15      > JMP                                                      ->38
    9    16    >   ASSIGN                                                   !5, !0
   10    17        INIT_FCALL                                               'array_splice'
         18        SEND_REF                                                 !5
         19        SEND_VAR                                                 !4
         20        SEND_VAL                                                 1
         21        DO_ICALL                                         $16     
         22        FETCH_DIM_R                                      ~17     $16, 0
         23        ASSIGN                                                   !6, ~17
   11    24        IS_NOT_EQUAL                                             !6, !3
         25      > JMPZ                                                     ~19, ->37
   12    26    >   ASSIGN                                                   !3, !6
   13    27        ASSIGN                                                   !7, !1
   14    28        INIT_FCALL                                               'array_unshift'
         29        SEND_REF                                                 !7
         30        SEND_VAR                                                 !6
         31        DO_ICALL                                                 
   15    32        INIT_FCALL_BY_NAME                                       'permuteUnique'
         33        SEND_VAR_EX                                              !5
         34        SEND_VAR_EX                                              !7
         35        SEND_VAR_EX                                              !2
         36        DO_FCALL                                      0          
    8    37    >   PRE_DEC                                                  !4
         38    >   IS_SMALLER_OR_EQUAL                                      0, !4
         39      > JMPNZ                                                    ~25, ->16
   18    40    > > RETURN                                                   !2
   20    41    > > RETURN                                                   null

End of function permuteunique

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.4 ms | 1403 KiB | 22 Q