Php array_rand random array value

Source: Internet
Author: User

Array_rand
(PHP 4 and PHP 5)

Array_rand-select an array of one or more random entries

Description
Hybrid array_rand (array $ input [Abstract $ num_req = 1])
Array_rand () is quite useful when you want to select an array of one or more random entries.

Parameters

Input
Input array.

Num_req
Specify the number of entries to select-if not specified, the default value is 1.


Return value
If you select only one entry, key random entries returned by array_rand. Otherwise, it returns a random entry of the key of an array. You can select any key and value array.

Instance

Example of #1 array_rand ()

<? Php
Srand (float) microtime () * 10000000 );
$ Input = array ("Neo", "Morpheus", "Trinity", "Cypher", "Tank ");
$ Rand_keys = array_rand ($ input, 2 );
Echo $ input [$ rand_keys [0]. "n ";
Echo $ input [$ rand_keys [1]. "n ";
?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.