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