Home > Backend Development > PHP Tutorial > How to get a random array list in php, get an array in php_PHP tutorial

How to get a random array list in php, get an array in php_PHP tutorial

WBOY
Release: 2016-07-13 10:14:16
Original
1195 people have browsed it

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.

www.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:...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template