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