★ wanayoo — archive 1999 http://www.php.net/manual/ja/function.array-rand.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to Arrays
Quick Reference
English version of this pageGerman version of this pageHungarian version of this page
Arrays
* array
* array_count_values
* array_diff
* array_flip
* array_intersect
* array_keys
* array_merge
* array_merge_recursive
* array_multisort
* array_pad
* array_pop
* array_push
* array_rand
* array_reverse
* array_shift
* array_slice
* array_splice
* array_unshift
* array_values
* array_walk
* arsort
* asort
* compact
* count
* current
* each
* end
* extract
* in_array
* key
* krsort
* ksort
* list
* next
* pos
* prev
* range
* reset
* rsort
* shuffle
* sizeof
* sort
* uasort
* uksort
* usort
Manual: array_rand
View the source code for this pageSearch the site



Previous page
 array_push
 Updated
Sat, 12 Aug 2000
array_reverse 
Next page


array_rand

(PHP4 >= 4.0.0)

array_rand -- 配列から一つ以上の要素をランダムに取得する

引数

mixed array_rand (array input [, int num_req])

array_rand()は、配列から一つ以上のランダムなエ ントリを取得しようとする場合に有用です。この関数は、配列 inputおよびオプションとして num_reqを引数とします。この引数は、取得す るエントリの数を指定します。指定されない場合は、デフォルトの1にな ります。

エントリを一つだけ取得する場合、array_rand()は ランダムなエントリのキーを返します。その他の場合は、ランダムなエ ントリのキーの配列を返します。これにより、ランダムなキーを取得し、 配列から値を取得することが可能になります。

乱数生成器を初期化するためにsrand()をコールす ることを忘れないで下さい。

例 1. array_rand()の例


srand((double)microtime() * 10000000);
$input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
$rand_keys = array_rand($input, 2);
print $input[$rand_keys[0]]."\n";
print $input[$rand_keys[1]]."\n";
      


 About Notes


Previous page
 array_push
 Updated
Sat, 12 Aug 2000
array_reverse 
Next page





Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.