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];
}

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

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