7.2.6、随机取出数组中的某个下标

 
 PHP Code  http://t.qq.com/tony-src/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
    
    /**
        array_rand 用来获取一个数组中的键,参数表示随机获取几个
     */

    
// 取出一个
    $fruit = array('banner','orange','apple');
    $a = array_rand($fruit,
1);
    
echo $a;
    
    
// 取出二个
    $fruit = array('banner','orange','apple');
    $a = array_rand($fruit,
2);
    
echo $a[0];
    
echo $a[1];
?>




原文地址:https://www.cnblogs.com/tonycody/p/2795379.html