mardi 11 août 2020

How to create an array without doubles values from random ints [duplicate]

I'm looking for a way to create an array with 6 random and unique ints. This is what I have so far but unfortunately it's not working correctly:

<?php
for ($i = 0; $i <= 5; $i++) {
    $values[$i] = array(
        rand($min = 1, $max = 10),
    );
    print_r($values[$i]);
    print "<br>";
    $values = array_unique($values);
    if ($values[$i] != null) {
        var_dump($values[$i]);
    } else {
        $values[$i] = array(
            rand($min = 1, $max = 10),
        );
    }
}

?>



Aucun commentaire:

Enregistrer un commentaire