Puoi usare questo codice:
<?php
function getWinnerPlayer($players) {
/* get total amount of tickets */
$total_tickets = 0;
foreach ($players as $player) {
/* var_dump($player->depositedValue); */
$total_tickets += $player->depositedValue * 100;
}
/* get winner ticket */
$winner = rand(1, $total_tickets);
/* return winner player */
$count = 0;
foreach ($players as $player) {
// $total_tickets is not the correct variable, sorry
// $count += $total_tickets->depositedValue * 100;
$count += $player->depositedValue * 100;
if ($count >= $winner) return $player;
}
}
?>