Hello!

I was a little confused, while using array_rand first time...
Please, take a look at the following code:
--->
    define("NUM", 2);
    $keys = array_rand(array(0,1,2,3,4,5), NUM);
    for ($i=0; $i < NUM; $i++)
        echo $i ." - " . $keys[$i] . "<br>";
<---

If NUM is greater then 1, everything is OK, but if it's equal to 1,
array_rand return not array, but a scalar! And it's necessary to write
special code, like the following:

--->
if (NUM == 1)
        $keys[0] = array_rand(array(0,1,2,3,4,5), NUM); // or $keys[0] = rand(0,
count(array(0,1,2,3,4,5)) - 1);
else
        $keys = array_rand(array(0,1,2,3,4,5), NUM);
<---

Any suggestions, how to make array_rand more flexible?

Best regards,
Andrew Kirilenko,
Seniour Programmer / System Administrator,
Internet Service.


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to