3v4l.org

run code in 300+ PHP versions simultaneously
<?php function random_pairs($letters) { $pairs = array(); $letters = array_filter($letters); while (count($letters) > 1) { $keys = array_keys($letters); shuffle($keys); list($letter1, $letter2) = array_slice($keys, 0, 2); $pairs[] = "$letter1$letter2"; $letters[$letter1]--; $letters[$letter2]--; $letters = array_filter($letters); } return array('pairs' => $pairs, 'unpaired' => $letters); } $letters = array('A' => 8, 'B' => 16, 'C' => 15, 'D' => 4, 'E' => 1); print_r(random_pairs($letters));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Q6NKN
function name:  (null)
number of ops:  8
compiled vars:  !0 = $letters
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   ASSIGN                                                   !0, <array>
   20     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'random_pairs'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function random_pairs:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 7
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 7
Branch analysis from position: 39
Branch analysis from position: 7
filename:       /in/Q6NKN
function name:  random_pairs
number of ops:  43
compiled vars:  !0 = $letters, !1 = $pairs, !2 = $keys, !3 = $letter1, !4 = $letter2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
    6     2        INIT_FCALL                                               'array_filter'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $6      
          5        ASSIGN                                                   !0, $6
    7     6      > JMP                                                      ->36
    8     7    >   INIT_FCALL                                               'array_keys'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $8      
         10        ASSIGN                                                   !2, $8
    9    11        INIT_FCALL                                               'shuffle'
         12        SEND_REF                                                 !2
         13        DO_ICALL                                                 
   10    14        INIT_FCALL                                               'array_slice'
         15        SEND_VAR                                                 !2
         16        SEND_VAL                                                 0
         17        SEND_VAL                                                 2
         18        DO_ICALL                                         $11     
         19        FETCH_LIST_R                                     $12     $11, 0
         20        ASSIGN                                                   !3, $12
         21        FETCH_LIST_R                                     $14     $11, 1
         22        ASSIGN                                                   !4, $14
         23        FREE                                                     $11
   11    24        NOP                                                      
         25        FAST_CONCAT                                      ~17     !3, !4
         26        ASSIGN_DIM                                               !1
         27        OP_DATA                                                  ~17
   12    28        FETCH_DIM_RW                                     $18     !0, !3
         29        PRE_DEC                                                  $18
   13    30        FETCH_DIM_RW                                     $20     !0, !4
         31        PRE_DEC                                                  $20
   14    32        INIT_FCALL                                               'array_filter'
         33        SEND_VAR                                                 !0
         34        DO_ICALL                                         $22     
         35        ASSIGN                                                   !0, $22
    7    36    >   COUNT                                            ~24     !0
         37        IS_SMALLER                                               1, ~24
         38      > JMPNZ                                                    ~25, ->7
   16    39    >   INIT_ARRAY                                       ~26     !1, 'pairs'
         40        ADD_ARRAY_ELEMENT                                ~26     !0, 'unpaired'
         41      > RETURN                                                   ~26
   17    42*     > RETURN                                                   null

End of function random_pairs

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.21 ms | 1403 KiB | 24 Q