3v4l.org

run code in 300+ PHP versions simultaneously
<?php $priorities = array( 6=> 10, 5=> 40, 4=> 35, 3=> 5, 2=> 5 ); # you put each of the values N times, based on N being the probability # each occurrence of the number in the array is a change it will get picked up # same is with lotteries $numbers = array(); foreach($priorities as $k=>$v){ for($i=0; $i<$v; $i++) $numbers[] = $k; } # then you just pick a random value from the array # the more occurrences, the more chances, and the occurrences are based on "priority" $entry = $numbers[array_rand($numbers)]; echo "x: ".$entry;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 7
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 7
Branch analysis from position: 12
Branch analysis from position: 7
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/iTk3W
function name:  (null)
number of ops:  22
compiled vars:  !0 = $priorities, !1 = $numbers, !2 = $v, !3 = $k, !4 = $i, !5 = $entry
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   13     1        ASSIGN                                                   !1, <array>
   14     2      > FE_RESET_R                                       $8      !0, ->13
          3    > > FE_FETCH_R                                       ~9      $8, !2, ->13
          4    >   ASSIGN                                                   !3, ~9
   15     5        ASSIGN                                                   !4, 0
          6      > JMP                                                      ->10
   16     7    >   ASSIGN_DIM                                               !1
          8        OP_DATA                                                  !3
   15     9        PRE_INC                                                  !4
         10    >   IS_SMALLER                                               !4, !2
         11      > JMPNZ                                                    ~14, ->7
   14    12    > > JMP                                                      ->3
         13    >   FE_FREE                                                  $8
   21    14        INIT_FCALL                                               'array_rand'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $15     
         17        FETCH_DIM_R                                      ~16     !1, $15
         18        ASSIGN                                                   !5, ~16
   22    19        CONCAT                                           ~18     'x%3A+', !5
         20        ECHO                                                     ~18
         21      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.38 ms | 1395 KiB | 15 Q