Conditions | 5 |
Paths | 7 |
Total Lines | 22 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
17 | protected static function get($items) { |
||
18 | if (is_array($items)) |
||
19 | { |
||
20 | $max = 0; |
||
21 | foreach ($items as $key => $value) { |
||
22 | $max += $value; |
||
23 | $items[$key] = $max; |
||
24 | } |
||
25 | |||
26 | $random = mt_rand(1, $max); |
||
27 | |||
28 | foreach ($items as $item => $max) |
||
29 | { |
||
30 | if ($random <= $max) { |
||
31 | break; |
||
32 | } |
||
33 | } |
||
34 | return $item; |
||
|
|||
35 | } else { |
||
36 | throw new Exception('Parameter must be an array.'); |
||
37 | |||
38 | return false; |
||
39 | } |
||
42 | } |