Okay,
I’ve been working on this for hours and I can get it close but just not there. I have the following code which randomizes a fixed array and returns 4 results.
[code=php]<?php
$cards = array(“ah”, “ac”, “ad”, “as”,
“2h”, “2c”, “2d”, “2s”,
“3h”, “3c”, “3d”, “3s”,
“4h”, “4c”, “4d”, “4s”,
“5h”, “5c”, “5d”, “5s”,
“6h”, “6c”, “6d”, “6s”,
“7h”, “7c”, “7d”, “7s”,
“8h”, “8c”, “8d”, “8s”,
“9h”, “9c”, “9d”, “9s”,
“th”, “tc”, “td”, “ts”,
“jh”, “jc”, “jd”, “js”,
“qh”, “qc”, “qd”, “qs”,
“kh”, “kc”, “kd”, “ks”);
srand(time());
for($i = 0; $i < 52; $i++)
{
$count = count($cards);
$random = (rand()%$count);
if($cards[$random] == “”)
{
$i–;
}
else
{
$deck[] = $cards[$random];
$cards[$random] = “”;
}
}
srand(time());
$starting_point = (rand()%51);
for ($index = 0; $index < 4; $index++)
{
if ($starting_point == 4) { $starting_point = 0; }
$shuf_deck = ($deck[$starting_point]);
$starting_point++;
}
?>
If I echo or print $shuf_deck I get a random 8 digit string along the lines of “2c9ckd3c”. This is mostly right. But what I need is to have the four pairs automatically assigned to variables. So for example, “2c9ckd3c” would be
$one = 2c;
$two = 9c;
etc.
I’ve been trying to use extract with no luck, but I need these 4 pairs of characters to later be inserted into different columns on a table.
Any help would really be appreciated.
Thanks