|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-04-10 20:29 UTC] sniper@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 22:00:02 2025 UTC |
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 )