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 = []): array { if (count($letters) < 2) { $result['unpaired'] = $letters; return $result; } $keys = array_rand($letters, 2); shuffle($keys); $result['paired'][] = $keys[0] . $keys[1]; --$letters[$keys[0]]; --$letters[$keys[1]]; return randomPairs(array_filter($letters), $result); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/v0btr
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
    5     6        DO_ICALL                                                 
   20     7      > RETURN                                                   1

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

End of function randompairs

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.36 ms | 1075 KiB | 17 Q