0
foreach(array_slice(glob('/res/images/*.jpg'), 0, 999) as $filename)

is work fine but

foreach(array_slice(glob('/res/images/*.jpg'), 0, 1000) as $filename)

doesnt work. Where is I can change such limit?

TKVideoChat
  • 61
  • 2
  • 7
  • 2
    Please expand on "doesn't work". What happens? Do you get an error? – IMSoP Feb 18 '14 at 11:22
  • Not show result. Thinks and nothing happens. 999 response time 2 sec, 1000 not responce – TKVideoChat Feb 18 '14 at 11:23
  • Maybe a [memory overflow](http://stackoverflow.com/a/12772851/1607098)? What about switching to [DirectoryIterator](http://php.net/directoryiterator)? – Touki Feb 18 '14 at 11:26

3 Answers3

3

Try with simple(May be the better) manner like

$i = 0;
foreach(glob('/res/images/*.jpg') as $filename) {
   if($i++ <= 1000) {
       // Do the display
   } else {
      break;
   }
}
GautamD31
  • 28,552
  • 10
  • 64
  • 85
0
$i = 0;
$max = 1000;
foreach(array_slice(glob('/res/images/*.jpg'), 0, $max) as $filename) {
   // Some code here
   if($i++ >= $max) break;
}
S.Thiongane
  • 6,883
  • 3
  • 37
  • 52
0

Try this

Shortest Way to do like so.

$i = 0;
foreach(array_slice(glob('/res/images/*.jpg'), 0, 1000) as $filename) {
   // Some code here
   if($i++ >= 1000) break;
}

I hope it will be helpful.

Govinda Rajbhar
  • 2,926
  • 6
  • 37
  • 62