Get the random array list program code in PHP _php tutorial

Source: Internet
Author: User
This article to introduce some commonly used PHP to get an array of random array of some instances of the program, I hope this method is helpful to all friends oh.

Paste a piece of code, get random array in PHP without much to say, direct code, PHP Array_rand is abnormal, break through the normal understanding, cumbersome

Example 1

The code is as follows Copy Code

function Create_random_ids ($min, $max, $limited)
{
$_base_ids = Range ($min, $max);
$_temp_key = Array_rand ($_base_ids,min (count ($_base_ids), $limited +10));
Stitching
$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 Copy Code

$a = array (0,1,2,3,4,5,6,7,8);
echo "$a the original order is:

";
foreach ($a as $v)
echo $v. " T ";
Shuffle ($a);
echo "
The order in which the $a is disrupted is: ";
foreach ($a as $v)
echo $v. " T ";
?>

The results for the first time are:

The result for the third time is:

http://www.bkjia.com/PHPjc/631246.html www.bkjia.com true http://www.bkjia.com/PHPjc/631246.html techarticle This article to introduce some commonly used PHP to get an array of random array of some instances of the program, I hope this method is helpful to all friends oh. Post a piece of code, get random in PHP ...

  • 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.