代码改变世界

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

2012-11-29 22:13  TONY|小四  阅读(461)  评论(0编辑  收藏  举报
 
 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];
?>