3v4l.org

run code in 300+ PHP versions simultaneously
<?php $payload = ['a', 'b', 'c', 'd']; function permutations($payload) { if (empty($payload)) { return [[]]; } $results = []; foreach ($payload as $key => $value) { foreach (permutations(array_diff_key($payload, [$key => $value])) as $subarray) { $results[] = array_merge([$value], $subarray); } } return $results; } $permutations = array_map('implode', permutations($payload)); print_r($permutations);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/vQmXh
function name:  (null)
number of ops:  13
compiled vars:  !0 = $payload, !1 = $permutations
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   20     1        INIT_FCALL                                               'array_map'
          2        SEND_VAL                                                 'implode'
          3        INIT_FCALL                                               'permutations'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $3      
          6        SEND_VAR                                                 $3
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !1, $4
   21     9        INIT_FCALL                                               'print_r'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Function permutations:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 28
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 28
Branch analysis from position: 7
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 26
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 26
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
filename:       /in/vQmXh
function name:  permutations
number of ops:  31
compiled vars:  !0 = $payload, !1 = $results, !2 = $value, !3 = $key, !4 = $subarray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        ISSET_ISEMPTY_CV                                         !0
          2      > JMPZ                                                     ~5, ->4
    7     3    > > RETURN                                                   <array>
   10     4    >   ASSIGN                                                   !1, <array>
   11     5      > FE_RESET_R                                       $7      !0, ->28
          6    > > FE_FETCH_R                                       ~8      $7, !2, ->28
          7    >   ASSIGN                                                   !3, ~8
   12     8        INIT_FCALL_BY_NAME                                       'permutations'
          9        INIT_FCALL                                               'array_diff_key'
         10        SEND_VAR                                                 !0
         11        INIT_ARRAY                                       ~10     !2, !3
         12        SEND_VAL                                                 ~10
         13        DO_ICALL                                         $11     
         14        SEND_VAR_NO_REF_EX                                       $11
         15        DO_FCALL                                      0  $12     
         16      > FE_RESET_R                                       $13     $12, ->26
         17    > > FE_FETCH_R                                               $13, !4, ->26
   13    18    >   INIT_FCALL                                               'array_merge'
         19        INIT_ARRAY                                       ~15     !2
         20        SEND_VAL                                                 ~15
         21        SEND_VAR                                                 !4
         22        DO_ICALL                                         $16     
         23        ASSIGN_DIM                                               !1
         24        OP_DATA                                                  $16
   12    25      > JMP                                                      ->17
         26    >   FE_FREE                                                  $13
   11    27      > JMP                                                      ->6
         28    >   FE_FREE                                                  $7
   17    29      > RETURN                                                   !1
   18    30*     > RETURN                                                   null

End of function permutations

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
130.22 ms | 1021 KiB | 18 Q