简体   繁体   中英

Shuffling a RecursiveIteratorIterator object in PHP

I'm trying to get the list of the files in a directory, but RecursiveIteratorIterator object gets them alphabetically. Is there any way to shuffle a RecursiveIteratorIterator object in PHP?

Thanks.

Shuffling an iterator does not make sense because you cannot know how to shuffle until you have seen the entirety of the results, and once you do that we 're no longer dealing with an iterator but rather with a materialized collection.

That means in the general case there is only a single option available:

$data = iterator_to_array($iterator);
shuffle($data);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM