December 23, 2012

How to print just a few from an array instead of all in php

Question by Marqeeu Rahfis

This is part of the working code that shows the entire array;

$files = filelist("./",1,1); // call the function
shuffle($files);
foreach ($files as $list) {//print array
echo "<a href="" . $list['name'] . "$startDir"><h4> " . $list['name'] . " </h4></a>";
//    echo "Directory: " . $list['dir'] . " => Level: " . $list['level'] . " => Name: " . $list['name'] . " => Path: " . $list['path'] ."<br>";

How do I modify it so that it only displays 10 or 15 list instead of all?

Answer by Starx

If you know the keys or indexes of the array you can do what KingCrunch is doing a lot faster by simple for loop

for($i=0; $i<=14; $i++) {
   // echo $file[$i];
}
...

Please fill the form - I will response as fast as I can!