|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-11-17 12:00 UTC] alisovoi at hotmail dot com
Description:
------------
$array[array_rand($array)] is always the same element of the array.
The server uses php.ini-recommended for the configuration.
(In PHP 4.3.2, this problem is non-existant. PHP 4.3.4 has this bug)
Reproduce code:
---------------
<?php
$random_sayings = array('Hey, this is not','randomly chosen','elements from an array');
echo($random_sayings[array_rand($random_sayings)]);
?>
Expected result:
----------------
Either one of the 3 elements of the array.
Actual result:
--------------
The same element no matter how many times the user refreshes.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 09:00:01 2025 UTC |
Can't confirm under same OS. I used a easier test case. ----- <?php $random_sayings = array('Hey, this is not','randomly chosen','elements from an array'); $i = 0; echo '<pre>'; while ($i < 1000) { print $random_sayings[array_rand($random_sayings)] . "\n"; ++$i; } echo '</pre>'; ?>