$files = filelist("./",1,1); // call the function shuffle($files); foreach ($files as $list) {//print array echo "

" . $list['name'] . "

"; // echo "Directory: " . $list['dir'] . " => Level: " . $list['level'] . " => Name: " . $list['name'] . " => Path: " . $list['path'] ."
"; $counter = 0; foreach ($files as $list) {//print array // your loop code here... $counter++; if ($counter > 10) break; } for($i=0; $i<=14; $i++) { // echo $file[$i]; } foreach(array_slice($files, 0, 15) as $file) { /* your code here */ } foreach (array_rand($files, 15) as $key) { $file = $files[$key]; // Your code here }