3v4l.org

run code in 300+ PHP versions simultaneously
<?php $set1 = ['A', 'B', 'C']; $set2 = [1, 2, 3]; function perms( $set1, $set2) { $perms = array(); $i = count( $set1); while( $i > 0) { $perms[] = p( $set1, $set2); $j = count( $set2); while( $j > 0) { $set2[] = array_shift( $set2); $perms[] = p( $set1, $set2); $j--; } $set1[] = array_shift( $set1); $i--; } return array_unique( $perms); } function p( $set1, $set2) { $p = array(); for( $i = 0; $i < count( $set1); $i++) { $el1 = $set1[ $i ]; $el2 = $set2[ $i ]; $p[] = $el1.$el2; } sort( $p); return implode( ', ', $p); } print_r( perms( $set1, $set2));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2poIf
function name:  (null)
number of ops:  10
compiled vars:  !0 = $set1, !1 = $set2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    3     1        ASSIGN                                                   !1, <array>
   35     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL                                               'perms'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

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

End of function perms

Function p:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 5
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 5
Branch analysis from position: 16
Branch analysis from position: 5
filename:       /in/2poIf
function name:  p
number of ops:  25
compiled vars:  !0 = $set1, !1 = $set2, !2 = $p, !3 = $i, !4 = $el1, !5 = $el2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   25     2        ASSIGN                                                   !2, <array>
   26     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->13
   27     5    >   FETCH_DIM_R                                      ~8      !0, !3
          6        ASSIGN                                                   !4, ~8
   28     7        FETCH_DIM_R                                      ~10     !1, !3
          8        ASSIGN                                                   !5, ~10
   29     9        CONCAT                                           ~13     !4, !5
         10        ASSIGN_DIM                                               !2
         11        OP_DATA                                                  ~13
   26    12        PRE_INC                                                  !3
         13    >   COUNT                                            ~15     !0
         14        IS_SMALLER                                               !3, ~15
         15      > JMPNZ                                                    ~16, ->5
   31    16    >   INIT_FCALL                                               'sort'
         17        SEND_REF                                                 !2
         18        DO_ICALL                                                 
   32    19        INIT_FCALL                                               'implode'
         20        SEND_VAL                                                 '%2C+'
         21        SEND_VAR                                                 !2
         22        DO_ICALL                                         $18     
         23      > RETURN                                                   $18
   33    24*     > RETURN                                                   null

End of function p

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.39 ms | 1398 KiB | 24 Q