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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 10:01:32 2024 UTC