note 73710 deleted from function.rand by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: palmnet at gmail dot com 

----

kurtubba's code was helpful, but didn't quite work for me.
Here's my version in case anyone has the same issue:
<?php
function UniqueRands($min, $max, $keys){
    static $retval = array();

    $x = rand($min,$max);

    if(!in_array($x,$retval)){
        array_push($retval, $x);
    }
    if($keys > count($retval)){
        UniqueRands($min, $max, $keys);
    }
    return $retval;
}

$var = UniqueRands(1, 4, 4);
print_r($var);

?>

Bear in mind I'm not the best with php! But my version worked for me at least.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.