3v4l.org

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

Function randompairs:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 4
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 31, Position 2 = 4
Branch analysis from position: 31
Branch analysis from position: 4
filename:       /in/f0sZv
function name:  randomPairs
number of ops:  37
compiled vars:  !0 = $letters, !1 = $result, !2 = $keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   10     1        ASSIGN_DIM                                               !1, 'paired'
          2        OP_DATA                                                  <array>
   11     3      > JMP                                                      ->28
   12     4    >   INIT_FCALL                                               'array_rand'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 2
          7        DO_ICALL                                         $4      
          8        ASSIGN                                                   !2, $4
   13     9        INIT_FCALL                                               'shuffle'
         10        SEND_REF                                                 !2
         11        DO_ICALL                                                 
   14    12        FETCH_DIM_R                                      ~9      !2, 0
         13        FETCH_DIM_R                                      ~10     !2, 1
         14        CONCAT                                           ~11     ~9, ~10
         15        FETCH_DIM_W                                      $7      !1, 'paired'
         16        ASSIGN_DIM                                               $7
         17        OP_DATA                                                  ~11
   15    18        FETCH_DIM_R                                      ~12     !2, 0
         19        FETCH_DIM_RW                                     $13     !0, ~12
         20        PRE_DEC                                                  $13
   16    21        FETCH_DIM_R                                      ~15     !2, 1
         22        FETCH_DIM_RW                                     $16     !0, ~15
         23        PRE_DEC                                                  $16
   17    24        INIT_FCALL                                               'array_filter'
         25        SEND_VAR                                                 !0
         26        DO_ICALL                                         $18     
         27        ASSIGN                                                   !0, $18
   11    28    >   COUNT                                            ~20     !0
         29        IS_SMALLER                                               1, ~20
         30      > JMPNZ                                                    ~21, ->4
   19    31    >   ASSIGN_DIM                                               !1, 'unpaired'
         32        OP_DATA                                                  !0
   20    33        VERIFY_RETURN_TYPE                                       !1
         34      > RETURN                                                   !1
   21    35*       VERIFY_RETURN_TYPE                                       
         36*     > RETURN                                                   null

End of function randompairs

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.86 ms | 1400 KiB | 21 Q