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