In the numbers, is it a random display?

Source: Internet
Author: User
 $arry = array('A','B','C','D');$result = array_rand($arry,2);foreach ($result as $val) {echo $arry["$val"].""; }

Please ask, this will produce 2 group ABCD combinations such as BC DC AB, etc.
But what I'm trying to show is, just show one. Random from a number of a or B or C or D
Please ask how to do this?
I changed 2 to 1 and I lost it.

Reply content:

 $arry = array('A','B','C','D');$result = array_rand($arry,2);foreach ($result as $val) {echo $arry["$val"].""; }

Please ask, this will produce 2 group ABCD combinations such as BC DC AB, etc.
But what I'm trying to show is, just show one. Random from a number of a or B or C or D
Please ask how to do this?
I changed 2 to 1 and I lost it.

mixed array_rand ( array $array [, int $num = 1 ] )# Picks one or more random entries out of an array, and returns the key (or keys) of the random entries. It uses a pseudo random number generator that is not suitable for cryptographic purposes.

The keys in the specified array are returned randomly, and $num multiple keys are returned as a key or in 数组 the form of requirements.

If you have an array


  
   

现在想每次随机输出数组中的一个元素,则可以采用以下方式获取:

 

以此同理可以实现其他的随机元素键并获取数组的随机元素。

 $array = Array (' A ', ' B ', ' C ', ' D '); $newArray = $array; Shuffle ($newArray); echo $newArray [0];  

Picks one or more random entries out of an arr Ay, and returns the key
(or keys) of the random entries. It uses a pseudo random number
Generator that's not suitable for cryptographic purposes.

If the second argument is 1 or not, the return is not an array, but just a number

 $ result = Array_rand ($arry, 2); is an array of * * * such as [Array_rand] $result = ($arry, 1); Just A * * number * * such as 1, not [1]  
  • 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.