Php 我如何随机化foreach(glob)的顺序?
我得到了一个位于特定目录中的所有PDF的列表,但我想让它成为一个随机列表,每次加载页面时都会改变顺序。我会在这里使用shuffle()吗?如果是,如何使用Php 我如何随机化foreach(glob)的顺序?,php,sorting,shuffle,Php,Sorting,Shuffle,我得到了一个位于特定目录中的所有PDF的列表,但我想让它成为一个随机列表,每次加载页面时都会改变顺序。我会在这里使用shuffle()吗?如果是,如何使用 foreach(glob('../'.$town_array['city'].'/*.pdf') as $filename){ 谢谢您可以在这里使用shuffle(): $pdfs = glob('../'.$town_array['city'].'/*.pdf'); shuffle($pdfs); foreach($pdfs as $
foreach(glob('../'.$town_array['city'].'/*.pdf') as $filename){
谢谢您可以在这里使用
shuffle()
:
$pdfs = glob('../'.$town_array['city'].'/*.pdf');
shuffle($pdfs);
foreach($pdfs as $filename){ … }
将全局返回存储在一个var中,并将其洗牌。然后循环遍历该var