Home >Backend Development >PHP Tutorial > 随机排列,该如何解决

随机排列,该如何解决

WBOY
WBOYOriginal
2016-06-13 12:58:54832browse

随机排列

本帖最后由 leeker7 于 2012-11-21 17:29:47 编辑
<br />
$arr=array(<br />
'1:xxx',<br />
'2:xxx',<br />
'3:xxx',<br />
'4:xxx',<br />
'5:xxx',<br />
'6:xxx',<br />
'7:xxx',<br />
'8:xxx',<br />
'9:xxx',<br />
'100:xxx'<br />
);<br />
$keys=array_rand($arr,8);<br />
foreach($keys as $k) echo $arr[$k].'';<br />

 这个代码是从上述10行里面随机取八行并echo出来
我想问的是
怎么才能把这8行在表达出来前
再进行次随机排列
然后再echo出来
谢谢
------解决方案--------------------
$keys=array_rand($arr,8);
shuffle($keys);
foreach($keys as $k) echo $arr[$k].'';
Statement:
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