php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32656 array_rand does not return array
Submitted: 2005-04-10 17:21 UTC Modified: 2005-04-10 20:29 UTC
From: yagi at thinkware dot jp Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.3.11 OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: yagi at thinkware dot jp
New email:
PHP Version: OS:

 

 [2005-04-10 17:21 UTC] yagi at thinkware dot jp
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
)      

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-10 20:29 UTC] sniper@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC