Which of the following is displayed in the data group?

Source: Internet
Author: User
{Code ...} please ask if this will lead to a combination of two groups of ABCD, such as BCDCAB, but what I want to tell you is that you only need to show one as long as the machine is transferred from the data group. a, B, C, or D. how can this problem be solved? After I change 2 to 1, I lose my account.
 $arry = array('A','B','C','D');$result = array_rand($arry,2);foreach ($result as $val) {echo $arry["$val"].""; }

Could you tell me how this will lead to the production of two groups of ABCD, such as bc dc AB?
But what I want to explain is that as long as one is displayed, the host displays A, B, C, or D from the data group.
How can this problem be solved?
After I change 2 to 1, I lose my account.

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

Could you tell me how this will lead to the production of two groups of ABCD, such as bc dc AB?
But what I want to explain is that as long as one is displayed, the host displays A, B, C, or D from the data group.
How can this problem be solved?
After I change 2 to 1, I lose my account.

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 randomly returned.$numReturns a key orArrayReturns multiple keys.

If you have an array


  

If you want to randomly output an element in the array, you can use the following method:

 

Similarly, other random element keys can be implemented and random elements of the array can be obtained.

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

Picks one or more random entries out of an array, and returnsThe key
(Or keys)Of the random entries. It uses a pseudo random number
Generator that is not suitable for cryptographic purposes.

If the second parameter is 1 or not, the returned result is not an array, but a number.

$ Result = array_rand ($ arry, 2); // Is an ** array ** such as [1, 2, 3] $ result = array_rand ($ arry, 1 ); // It is just a ** number ** such as 1, not [1]

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.