From:             yagi at thinkware dot jp
Operating system: any
PHP version:      4.3.11
PHP Bug Type:     *General Issues
Bug description:  array_rand does not return array

Description:
------------
array_rand doesn't return array but a key as string when 
given mixed array which has only one value(and key).

Reproduce code:
---------------
$array = array("test");
$rand_key = array_rand($array, count($array));
print_r($rand_key);

print("\n");

$array2 = array("test" => "value");
$rand_key2 = array_rand($array2, count($array2));
print_r($rand_key2);

print("\n");

$array3 = array("test" => "value", "test2" => "value2");
$rand_key3 = array_rand($array3, count($array3));
print_r($rand_key3);

print("\n"); 

Expected result:
----------------
Array([0] => 0)
Array([0] => test)
Array
(
    [0] => test
    [1] => test2
)
*the last one is right. Above two are not expected 
result.

Actual result:
--------------
0
test
Array
(
    [0] => test
    [1] => test2
)      

-- 
Edit bug report at http://bugs.php.net/?id=32656&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=32656&r=trysnapshot4
Try a CVS snapshot (php5.0): 
http://bugs.php.net/fix.php?id=32656&r=trysnapshot50
Try a CVS snapshot (php5.1): 
http://bugs.php.net/fix.php?id=32656&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=32656&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=32656&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=32656&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=32656&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=32656&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=32656&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=32656&r=notwrong
Not enough info:             
http://bugs.php.net/fix.php?id=32656&r=notenoughinfo
Submitted twice:             
http://bugs.php.net/fix.php?id=32656&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=32656&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=32656&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=32656&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=32656&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=32656&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=32656&r=float
No Zend Extensions:          http://bugs.php.net/fix.php?id=32656&r=nozend
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=32656&r=mysqlcfg

Reply via email to