PHP gets a list of random array methods, PHP get array _php tutorial

Source: Internet
Author: User

PHP gets a list of random arrays, PHP gets the array


In this paper, the example of PHP gets an array of random array of instances of the program, shared for everyone to reference. The implementation method is as follows:

Needless to say, the direct code, PHP Array_rand is abnormal, break through the understanding of normal people, very cumbersome
Example 1:
Copy the Code code 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));
Stitching
$ids = Array ();
for ($x =0; $x < count ($_temp_key); $x + +) {
$ids [] = $_base_ids[$_temp_key[$x]];
}
return $ids;
}
Example 2:
Copy the Code code as follows: <?php
$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 results for the second time are:

The result for the third time is:

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/910590.html www.bkjia.com true http://www.bkjia.com/PHPjc/910590.html techarticle PHP Gets a list of random arrays, PHP gets an array of examples in this article about PHP get an array of random array of instances of the program, shared for everyone to reference. The concrete 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.