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?

3
  • 2
    Please expand on "doesn't work". What happens? Do you get an error? Commented Feb 18, 2014 at 11:22
  • Not show result. Thinks and nothing happens. 999 response time 2 sec, 1000 not responce Commented Feb 18, 2014 at 11:23
  • Maybe a memory overflow? What about switching to DirectoryIterator? Commented Feb 18, 2014 at 11:26

3 Answers 3

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;
   }
}
Sign up to request clarification or add additional context in comments.

3 Comments

For huge amount of possible files, I suggest to break in else block.
Thanks @PavelŠtěrba I have added it now.Actually I forgot it
Or to simplify slightly, put if($i++ > 1000) { break; } at the top of the function, saving the extra indenting. However, I suspect this won't solve the OP's problem.
0
$i = 0;
$max = 1000;
foreach(array_slice(glob('/res/images/*.jpg'), 0, $max) as $filename) {
   // Some code here
   if($i++ >= $max) break;
}

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.