3v4l.org

run code in 300+ PHP versions simultaneously
<?php function randomizer($sArray, $target) { $b = (count($sArray)/2); // Randomize count for better result make it half of the total array count $c = floor($target/$b); // Loop Count $r = $target-($b*$c); // Rest of the Count $cardsList = array(); if($c > 0){ /* Now Loop for Full Number */ for($i=0; $i<$c; $i++){ $cardsList = array_merge($cardsList,array_rand($sArray, $b)); } if($r >= 1){ $restArray = array_rand($sArray, $r); if(is_array($restArray)){ $cardsList = array_merge($cardsList,$restArray); }else{ $cardsList[] = $restArray; } } }else{ $cardsList = array_merge($cardsList,array_rand($sArray, $target)); } return $cardsList; } //only 8 values $sArray = range('A', 'H'); $resultArray = randomizer($sArray, 67); echo 'Amount 50 - result: ' . count($resultArray) . \PHP_EOL; print_r($resultArray);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tPc7A
function name:  (null)
number of ops:  18
compiled vars:  !0 = $sArray, !1 = $resultArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   INIT_FCALL                                               'range'
          1        SEND_VAL                                                 'A'
          2        SEND_VAL                                                 'H'
          3        DO_ICALL                                         $2      
          4        ASSIGN                                                   !0, $2
   31     5        INIT_FCALL                                               'randomizer'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 67
          8        DO_FCALL                                      0  $4      
          9        ASSIGN                                                   !1, $4
   32    10        COUNT                                            ~6      !1
         11        CONCAT                                           ~7      'Amount+50+-++result%3A+', ~6
         12        CONCAT                                           ~8      ~7, '%0A'
         13        ECHO                                                     ~8
   33    14        INIT_FCALL                                               'print_r'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                                 
         17      > RETURN                                                   1

Function randomizer:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 48
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 18
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 47
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 45
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
Branch analysis from position: 47
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 18
Branch analysis from position: 30
Branch analysis from position: 18
Branch analysis from position: 48
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tPc7A
function name:  randomizer
number of ops:  59
compiled vars:  !0 = $sArray, !1 = $target, !2 = $b, !3 = $c, !4 = $r, !5 = $cardsList, !6 = $i, !7 = $restArray
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        COUNT                                            ~8      !0
          3        DIV                                              ~9      ~8, 2
          4        ASSIGN                                                   !2, ~9
    6     5        INIT_FCALL                                               'floor'
          6        DIV                                              ~11     !1, !2
          7        SEND_VAL                                                 ~11
          8        DO_ICALL                                         $12     
          9        ASSIGN                                                   !3, $12
    7    10        MUL                                              ~14     !2, !3
         11        SUB                                              ~15     !1, ~14
         12        ASSIGN                                                   !4, ~15
    8    13        ASSIGN                                                   !5, <array>
    9    14        IS_SMALLER                                               0, !3
         15      > JMPZ                                                     ~18, ->48
   11    16    >   ASSIGN                                                   !6, 0
         17      > JMP                                                      ->28
   12    18    >   INIT_FCALL                                               'array_merge'
         19        SEND_VAR                                                 !5
         20        INIT_FCALL                                               'array_rand'
         21        SEND_VAR                                                 !0
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                         $20     
         24        SEND_VAR                                                 $20
         25        DO_ICALL                                         $21     
         26        ASSIGN                                                   !5, $21
   11    27        PRE_INC                                                  !6
         28    >   IS_SMALLER                                               !6, !3
         29      > JMPNZ                                                    ~24, ->18
   14    30    >   IS_SMALLER_OR_EQUAL                                      1, !4
         31      > JMPZ                                                     ~25, ->47
   15    32    >   INIT_FCALL                                               'array_rand'
         33        SEND_VAR                                                 !0
         34        SEND_VAR                                                 !4
         35        DO_ICALL                                         $26     
         36        ASSIGN                                                   !7, $26
   16    37        TYPE_CHECK                                  128          !7
         38      > JMPZ                                                     ~28, ->45
   17    39    >   INIT_FCALL                                               'array_merge'
         40        SEND_VAR                                                 !5
         41        SEND_VAR                                                 !7
         42        DO_ICALL                                         $29     
         43        ASSIGN                                                   !5, $29
   16    44      > JMP                                                      ->47
   19    45    >   ASSIGN_DIM                                               !5
         46        OP_DATA                                                  !7
    9    47    > > JMP                                                      ->57
   23    48    >   INIT_FCALL                                               'array_merge'
         49        SEND_VAR                                                 !5
         50        INIT_FCALL                                               'array_rand'
         51        SEND_VAR                                                 !0
         52        SEND_VAR                                                 !1
         53        DO_ICALL                                         $32     
         54        SEND_VAR                                                 $32
         55        DO_ICALL                                         $33     
         56        ASSIGN                                                   !5, $33
   25    57    > > RETURN                                                   !5
   26    58*     > RETURN                                                   null

End of function randomizer

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.11 ms | 1015 KiB | 19 Q