brsy
nah mang
- May 12, 2011
- 1,530
- 272
So basically, when someone enters $1.00 into a raffle, they get a ticket per cent entered, in an ascending order.
How can I check which user the winning ticket belongs to?
- So if user 1 enters $4.31, user 2 enters $1.09, and user 3 enters $6, there would be a total of 1,140 tickets in the raffle.
- User 1 would have ticket numbers 1 through 431, because he entered the first 431 tickets into the raffle, and user 2 would have tickets 432 through 540, because he entered the next 109 tickets, and user 3 would have tickets 542 through 1,140.
How can I check which user the winning ticket belongs to?
PHP:
<?php
$user = array('$4.31', '$1.09', '$6.00');
$oldTotal = 0;
foreach($user as $number) {
$number = str_replace('$', '', $number);
$number = str_replace('.', '', $number);
settype($number, "integer");
$total = $number + $oldTotal;
$oldTotal = $total;
}
foreach($user as $blessed) {
$blessed = str_replace('$', '', $blessed);
$blessed = str_replace('.', '', $blessed);
echo $blessed . " tickets – " . round($blessed / $total * 100, 2) ."% chance<br>";
}
echo "<br>Total Tickets: ".$total . "<br>";
echo "Winning Ticket: ". rand(1, $total);
?>
Last edited by a moderator: