Php to obtain the random array list, php to get the array _ PHP Tutorial

Source: Internet
Author: User
Php is used to obtain the random array list. php is used to obtain the array. Php: how to obtain the random array list. php: how to obtain the array. This article describes how to use php to obtain the random array instance program. The specific implementation method is as follows: php obtains the random array list, and php obtains the array

This article describes how to use php to obtain random arrays in an array. The specific implementation method is as follows:

Needless to say, directly paste the code. the array_rand in php is abnormal, which breaks through the understanding of normal people and is very tedious.
Example 1:

The code is as follows:

Function create_random_ids ($ min, $ max, $ limited)
{
$ _ Base_ids = range ($ min, $ max );
$ _ Temp_key = array_rand ($ _ base_ids, min (count ($ _ base_ids), $ limited + 10 ));
// Splicing
$ Ids = array ();
For ($ x = 0; $ x <count ($ _ temp_key); $ x ++ ){
$ Ids [] = $ _ base_ids [$ _ temp_key [$ x];
}
Return $ ids;
}


Example 2:

The code is as follows:

<? Php
$ A = array (, 8 );
The original order of echo "$ a is:

";
Foreach ($ a as $ v)
Echo $ v. "t ";
Shuffle ($ );
Echo"
$ A is in the following order: ";
Foreach ($ a as $ v)
Echo $ v. "t ";
?>


The first result is:

The second result is:

The third result is:

I hope this article will help you with php programming.

Examples in this article describes how to use php to obtain random arrays from arrays and share them with you for your reference. The specific implementation method is as follows :...

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.