3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ 1,2,3,4 ]; $expected = [ '1-2-3-4', '2-1-3-4', '3-1-2-4', '1-3-2-4', '2-3-1-4', '3-2-1-4', '4-2-1-3', '2-4-1-3', '1-4-2-3', '4-1-2-3', '2-1-4-3', '1-2-4-3', '1-3-4-2', '3-1-4-2', '4-1-3-2', '1-4-3-2', '3-4-1-2', '4-3-1-2', '4-3-2-1', '3-4-2-1', '2-4-3-1', '4-2-3-1', '3-2-4-1', '2-3-4-1', ]; function mixture( $size, array &$collection ) { $permutations = []; $offset = $size - 1; if ( 1 === $size ) { $permutations[] = implode( '-', $collection ); return $permutations; } for ( $i = 0; $i < $offset; $i++ ) { $permutations = array_merge( $permutations, mixture( $offset, $collection ) ); $j = ( 0 == $size % 2 ) ? $i : 0; $tmp_el = $collection[ $offset ]; $collection[ $offset ] = $collection[ $j ]; $collection[ $j ] = $tmp_el; } $permutations = array_merge( $permutations, mixture( $offset, $collection ) ); return $permutations; } print_r($permutations = mixture( count($arr), $arr )); if ($expected == $permutations) { echo 'PASS'.PHP_EOL; } else { echo 'FAIL'.PHP_EOL; echo 'missing: '.PHP_EOL; print_r(array_diff($expected, array_unique($permutations))); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 15
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7Vn2p
function name:  (null)
number of ops:  28
compiled vars:  !0 = $arr, !1 = $expected, !2 = $permutations
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, <array>
   55     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL                                               'mixture'
          4        COUNT                                            ~5      !0
          5        SEND_VAL                                                 ~5
          6        SEND_REF                                                 !0
          7        DO_FCALL                                      0  $6      
          8        ASSIGN                                           ~7      !2, $6
          9        SEND_VAL                                                 ~7
         10        DO_ICALL                                                 
   57    11        IS_EQUAL                                                 !1, !2
         12      > JMPZ                                                     ~9, ->15
   58    13    >   ECHO                                                     'PASS%0A'
         14      > JMP                                                      ->27
   60    15    >   ECHO                                                     'FAIL%0A'
   61    16        ECHO                                                     'missing%3A+%0A'
   62    17        INIT_FCALL                                               'print_r'
         18        INIT_FCALL                                               'array_diff'
         19        SEND_VAR                                                 !1
         20        INIT_FCALL                                               'array_unique'
         21        SEND_VAR                                                 !2
         22        DO_ICALL                                         $10     
         23        SEND_VAR                                                 $10
         24        DO_ICALL                                         $11     
         25        SEND_VAR                                                 $11
         26        DO_ICALL                                                 
   63    27    > > RETURN                                                   1

Function mixture:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 16
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 16
Branch analysis from position: 42
Branch analysis from position: 16
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 16
Branch analysis from position: 42
Branch analysis from position: 16
filename:       /in/7Vn2p
function name:  mixture
number of ops:  53
compiled vars:  !0 = $size, !1 = $collection, !2 = $permutations, !3 = $offset, !4 = $i, !5 = $j, !6 = $tmp_el
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   34     2        ASSIGN                                                   !2, <array>
   35     3        SUB                                              ~8      !0, 1
          4        ASSIGN                                                   !3, ~8
   37     5        IS_IDENTICAL                                             !0, 1
          6      > JMPZ                                                     ~10, ->14
   38     7    >   INIT_FCALL                                               'implode'
          8        SEND_VAL                                                 '-'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $12     
         11        ASSIGN_DIM                                               !2
         12        OP_DATA                                                  $12
   39    13      > RETURN                                                   !2
   42    14    >   ASSIGN                                                   !4, 0
         15      > JMP                                                      ->40
   43    16    >   INIT_FCALL                                               'array_merge'
         17        SEND_VAR                                                 !2
         18        INIT_FCALL_BY_NAME                                       'mixture'
         19        SEND_VAR_EX                                              !3
         20        SEND_VAR_EX                                              !1
         21        DO_FCALL                                      0  $14     
         22        SEND_VAR                                                 $14
         23        DO_ICALL                                         $15     
         24        ASSIGN                                                   !2, $15
   45    25        MOD                                              ~17     !0, 2
         26        IS_EQUAL                                                 ~17, 0
         27      > JMPZ                                                     ~18, ->30
         28    >   QM_ASSIGN                                        ~19     !4
         29      > JMP                                                      ->31
         30    >   QM_ASSIGN                                        ~19     0
         31    >   ASSIGN                                                   !5, ~19
   46    32        FETCH_DIM_R                                      ~21     !1, !3
         33        ASSIGN                                                   !6, ~21
   47    34        FETCH_DIM_R                                      ~24     !1, !5
         35        ASSIGN_DIM                                               !1, !3
         36        OP_DATA                                                  ~24
   48    37        ASSIGN_DIM                                               !1, !5
         38        OP_DATA                                                  !6
   42    39        PRE_INC                                                  !4
         40    >   IS_SMALLER                                               !4, !3
         41      > JMPNZ                                                    ~27, ->16
   51    42    >   INIT_FCALL                                               'array_merge'
         43        SEND_VAR                                                 !2
         44        INIT_FCALL_BY_NAME                                       'mixture'
         45        SEND_VAR_EX                                              !3
         46        SEND_VAR_EX                                              !1
         47        DO_FCALL                                      0  $28     
         48        SEND_VAR                                                 $28
         49        DO_ICALL                                         $29     
         50        ASSIGN                                                   !2, $29
   52    51      > RETURN                                                   !2
   53    52*     > RETURN                                                   null

End of function mixture

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.15 ms | 1418 KiB | 24 Q