函数array_rand()不起作用[PHP]

时间:2016-02-02 21:11:02

标签: php arrays

我有阵列:

Array ( [0] => 1 [2] => 3 [3] => 4 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 [10] => 11 [11] => 12 [12] => 13 [13] => 14 [14] => 15 [15] => 16 [16] => 17 [17] => 18 [18] => 19 [20] => 21 [21] => 22 [22] => 23 ) 

我想绘制一个数字array_rand()

$rand_array = array_rand($new_array, 1);

但结果是0,5,20 - 这些数字不在数组中

1 个答案:

答案 0 :(得分:2)

$intRandomIndex = array_rand($new_array, 1);
echo $new_array[$intRandomIndex];

http://php.net/manual/en/function.array-rand.php