php random array - random again when doing while [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-13 09:45:05

问题


Right now, every single time I do a while do, it goes from top to bottom of my array. How can I make it go through each value but in a random mode, not from top to bottom?

Here's what I have:

$xbb = array('avotf1',
'avotf2',
'avotf3',
'avotf4',
'avotf5',
'avotf6',
'avotf7',
'avotf8',
'avotf9',
'avotf11',
'avotf12',
'avotf13',
'avotf14',
'avotf15',
'avotf10');

foreach($xbb as $item)
{

echo "$item<br>";

}

How do I shuffle the random array that I have and still show all 15 values?


回答1:


Shuffle it with shuffle():

shuffle($xbb);

Searching Google for php shuffle array will give you tons of results as well, by the way.



来源:https://stackoverflow.com/questions/15909116/php-random-array-random-again-when-doing-while

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!