Random 24 card sort algorythm [closed]

3 days ago 4
ARTICLE AD BOX

I make game card "pan" in PHP and I have problem. All works ok but when I sort 24 cards then card was double. Here is steps who do algorithm:

set while loop

set random number with 11-34 pule

if number exist then step back or if number not exist add number to string

set foreach function from the string

make array from string when index number is <12 and >13 and write to player1 and player2

when index number is 24 then break

Here is the code

$w = 1; $taliap = ""; $tlicz = 0; $taliap2 = ""; $tpom = ""; while ($w == 1) { $tpom = rand(11, 34); if (strstr($taliap, $tpom)) { } else { $tlicz = $tlicz + 1; $taliap = $taliap . "" . $tpom . ","; if ($tlicz >= 24) { $w = 2; } } } $tlicz2 = 0; $taliap2 = ""; $taliap3 = ""; $taliap4 = explode(",", $taliap); foreach ($taliap4 as $key) { $tlicz2 = $tlicz2 + 1; if ($tlicz2 <= 12) { $taliap2 = $taliap2 . $key . ","; } if ($tlicz2 >= 13) { if (!empty($key)) { $taliap3 = $taliap3 . $key . ","; } } } $fp = fopen("player1.txt", "w"); fputs($fp, $taliap2); fclose($fp); $fp = fopen("player2.txt", "w"); fputs($fp, $taliap3); fclose($fp);

what is wrong?

Read Entire Article