How to get a random array list in php, get an array in php
The example in this article describes the example program of obtaining a random array in an array in PHP, and shares it with you for your reference. The specific implementation method is as follows:
Needless to say, just post the code directly. array_rand in php is very abnormal, breaking through the understanding of normal people, and it is very cumbersome
Example 1:
Copy code 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:
Copy code The code is as follows:
$a = array(0,1,2,3,4,5,6,7,8);
echo "The original order of $a is:
";
foreach($a as $v)
echo $v."t";
shuffle($a);
echo "
The scrambled order of $a is:
";
foreach($a as $v)
echo $v."t";
?>
The result obtained for the first time is:
The result obtained for the second time is:
The result obtained for the third time is:
I hope this article will be helpful to everyone’s PHP programming design.
http://www.bkjia.com/PHPjc/910590.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/910590.htmlTechArticleHow to get a list of random arrays in php, get an array in php This article tells an example program of getting a random array in an array in php , shared with everyone for your reference. The specific implementation method is as follows:...