I have an variable called $result
that is an array containing upto 4 elements.
one of the elements can be an number, or an array containing multiple numbers.
The first element in $result
are the winner, the 2nd element is 2nd etc..
It can be multiple winners, 2nd winners, 3rd etc..
example:
$result = array(
1,
2,
array(3,4)
);
OR
$result = array(1,2,3);
OR
$result = array(array(1,2),array(1,2));
OR
$result = array(1,2,3,4);
etc..
this would mean that the winner is 1, the 2nd winner is 2, and theres a split 3rd place between 3 and 4. no 4th place as $result
only contains 3 elements.
Question: How can store the winners to be like this:
$data['winner'] = "The user Xwon"; OR "the user x and y won.. (or even more if there is even more winners somehow)";
// If there is 2nd place
do the same with 2nd.
// If there is 3rd..
same
// If there is 4th.
same
so $data
can contain an element for each of the winners, no matter if there multiple winners for that occurence or not?
If you have a better solution please share.
Brief question: How can i make the output of this variable better?/ best possible way?
Note: its important that all the first winner will be announced in a message.
$data['winner'] = "The user Xwon"; OR "the user x and y won.. (or even more if there is even more winners somehow)";
this is what i had from before, very poor made:
$winner = $result[0];
$differentWinners = count($result);
if (is_array($winner)) {
foreach($winner as $player) {
echo "winner is: $player <br>";
}
} else {
// echo "only winner is: $winner <br>";
}
$return['winner']['userid'] = $userIds[$winner];
$return['winner']['username'] = $this->user->userDetails($userIds[$winner])->username;
$winnerData = new pokerHand($test[$winner]);
$return['winner']['combination'] = $winnerData->printHand()['combination'];
$return['winner']['message'] = "THE AMAZING ".$return['winner']['username']." WON WITH ".$return['winner']['combination']." !";
if ($differentWinners == 2) {
$secound = $result[1];
if (is_array($secound)) {
foreach($secound as $player) {
echo "secound is: $player <br>";
}
} else {
echo "only secound is: $secound <br>";
}
}
if ($differentWinners == 3) {
$third = $result[2];
if (is_array($third)) {
foreach($third as $player) {
echo "third is: $player <br>";
}
} else {
echo "only third is: $third <br>";
}
}
if ($numbers == 4 and $differentWinners == 4) {
$forth = $result[3];
if (is_array($forth)) {
foreach($forth as $player) {
echo "forth is: $player <br>";
}
} else {
echo "only forth is: $winner <br>";
}
}
return $return;