Home > Article > Backend Development > Get random array list program code in php_PHP tutorial
This article will introduce to you some commonly used PHP example programs for obtaining random arrays in arrays. I hope this method will be helpful to all my friends.
Post a piece of code to get a random array in php. Needless to say, just post the code directly. array_rand in php is very abnormal, breaking through the understanding of normal people, and is cumbersome
Example 1
The code is as follows
| Copy code
| ||||
{
$_base_ids = range($min,$max); <img style="max-width:90%" alt="php 随机打乱一个数组的排序shuffle - 九重海 - jiuchonghai-PHP的博客" src="http://www.bkjia.com/uploads/allimg/131231/132F0A18-0.jpg" __1379995076531__="ev_3284125348">for ($x=0; $x < count($_temp_key); $x++) { $ids[] = $_base_ids[$_temp_key[$x]]; <strong>第二次得到的结果为: </strong>} <img style="max-width:90%" alt="php 随机打乱一个数组的排序shuffle - 九重海 - jiuchonghai-PHP的博客" src="http://www.bkjia.com/uploads/allimg/131231/132F04U9-1.jpg" __1379995076531__="ev_5189766409">Return $ids; <strong>第三次得到的结果为:<br></strong> <img style="max-width:90%" alt="php 随机打乱一个数组的排序shuffle - 九重海 - jiuchonghai-PHP的博客" src="http://www.bkjia.com/uploads/allimg/131231/132F03115-2.jpg" __1379995076531__="ev_6379571093">} |
Example 2