PHP Notice: Undefined offset: 1 while getting all directories -


so working dropdown menu select style people want choose, got error:

notice: undefined offset: 1 in ...

the code:

<?php $dirs=array_filter(glob('../styles/*'), 'is_dir'); $count=count($dirs); $i = $count; while($i>0){     echo substr($dirs[$i], 10);     $i=$i-1; } ?> 

i hope knows how fix error, many thanks!

it's because is_dir function removes items array not directories.
keys untouched.

you can use glob_onlydir flag instead of array_filter

<?php   $dirs   = glob( '../styles/*', glob_onlydir );   $count  = count( $dirs );   $i      = ( $count - 1 ); // note: must substract 1 total    while( $i >= 0 ) {     echo substr( $dirs[$i], 10 ); // assumes want first 10 chars, if yes use substr( $dirs[$i], 0, 10 )     $i--;   }    /** foreach loop **/   $dirs = glob( '../styles/*', glob_onlydir );   $dirs = array_reverse( $dirs );    foreach( $dirs $dir ) {     echo substr( $dir, 10 );   } ?> 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -