Welcome Guest, Not a member yet? Register   Sign In
notice when using file helper
#1

[eluser]Krystian[/eluser]
Hi,

when I use

Code:
$file = get_filenames('images/gallery/thumbs', false);
for( $i = 0 ; $i <= count($file) ; $i++ )
{
       echo $file[$i] . '<br />';
}
I receive proper files but also


A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 10
Filename: public/vertical_menu_page_view.php
Line Number: 99
#2

[eluser]Kamarg[/eluser]
Off by 1 error.

Use < instead of <=
#3

[eluser]Aken[/eluser]
It's also recommended to do the count function outside of the loop, otherwise it will run on every single loop iteration. Not a big deal for small loops, but it can be time consuming for more involved loops.
Code:
$count = count($file);

for ($i = 0; $i < $count; $i++)
{
  // ...
}




Theme © iAndrew 2016 - Forum software by © MyBB