vendredi 25 novembre 2016

in_array from array in txt file not working for int greater than ten

I've tried this

$randtxt = fopen('random.txt','r');
$zawa = fread($randtxt, 8192);
$tt = str_split($zawa);


do {

    $numer = rand(8, 11);

} while (in_array($numer, $tt));


echo<<<END
$numer
END;

Random.txt contains in this example:

"8", "9", "10", 

The only one solution for this script is 11 at the end, but it's 10 sometime too (I don't know why), it's sometime 10, but never 1, 2, 3 ... 9. It's not working for int greater than 10.

I've tried with this, but it's not even working too

$randtxt = file_get_contents('random.txt');
$inarr = unserialize($randtxt);

$number = 11;       

if (in_array($number, $inarr, true))
{
    echo "yup";
}
else
{
    echo "nope";
}

    $numberout = serialize($number);
    $out = file_put_contents('random.txt', $numberout, FILE_APPEND);




Aucun commentaire:

Enregistrer un commentaire