Here is the deal, working on a card game using php mysql, I have a very simple way of shuffling the deck and I use array_chunk() to divide the deck into hands, the number of cards in each hand is variable depending of the numbers of players, there is also an extra hand called the widow. I'm still a long way to get the game going but my problem at the moment is to be able to insert the hands in the database after the initial shuffling, any advice would be greatly appreciated.
Here is my code so far:
<?php
$deck = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52");
shuffle($deck);
$players = "5";
$hands = (int)(52/($players + 1)); //Number of players + 1 for the widow
$widow = (int)52%($players + 1); //one full hand + the remainder of the cards
$cards_per_hand = $hands = (int)(52/($players + 1));
echo "Player: $players";
echo "<br>Hand: $hands";
echo "<br>Widow: $widow";
//DEBUG
/*
echo "<pre>";
//print_r(array_chunk($deck, $hands));
print_r(array_chunk($deck, $hands, true));
echo "</pre>";
*/
$game = array_chunk($deck, $hands);
for ($deck= 0; $deck < ($players + 2); $deck++)
{
echo "<li><b>Player $deck</b>";
echo "<ul>";
for ($hands = 0; $hands < $cards_per_hand; $hands++)
{
//echo "<img src=\"http://www.cemond.com/RUMMOLI/Cards_1_52/".$game[$deck][$hands].".png\">";
echo "".$game[$deck][$hands].", ";
}
echo "</ul>";
echo "</li>";
}
?>
An here is a snapshot of what I can print on the screen.
Player 0
46, 12, 32, 42, 48, 13, 37, 20,
Player 1
4, 16, 40, 24, 22, 45, 15, 27,
Player 2
14, 50, 17, 49, 33, 31, 30, 18,
Player 3
26, 35, 51, 21, 29, 10, 7, 52,
Player 4
47, 5, 1, 8, 41, 25, 44, 23,
Player 5
38, 6, 39, 11, 43, 3, 19, 36,
Player 6
2, 28, 34, 9, , , , ,