random 24 card sort algorythm
09:18 01 Feb 2026

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

1 set while loop

2 set random number with 11-34 pule

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

5 set foreach function from the string

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

7 when index number is 24 then break

here is 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?

sorting random