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