Created
August 10, 2015 07:49
-
-
Save asad01304/55dd9339376434fefdf6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$items = array( | |
'original' => 50, | |
'v1' => 20, | |
'v2' => 10, | |
'v3' => 20, | |
); | |
$rand = rand(0,100); | |
$sum = 0; | |
foreach($items as $id => $item){ | |
$sum += $item; | |
if($rand <= $sum){ | |
echo "$id => $item \n"; | |
break; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment