im fairly new to php programming and i dont want to cause my server unnecessary load by ineffecient coding, as this script will be accessed a lot. could someone optimize this? thanks.
<?
//read directives, sort through array
if ($dir = @opendir('albums')) {
while (($file = readdir($dir)) !== false) {
if ($file != '.' && $file != '..') {
$files[] = array(name => $file);
}
}
}
closedir($dir);
sort($files);
//split array according to the first letter of the value
for ($i = 0; $i < count($files); $i++) {
if ($files[$i][name]{0} <= '9')
$files1[] = array(name => $files[$i][name]);
elseif ($files[$i][name]{0} <= 'f')
$files2[] = array(name => $files[$i][name]);
elseif ($files[$i][name]{0} <= 'l')
$files3[] = array(name => $files[$i][name]);
elseif ($files[$i][name]{0} <= 'r')
$files4[] = array(name => $files[$i][name]);
elseif ($files[$i][name]{0} <= 'z')
$files5[] = array(name => $files[$i][name]);
}
//echo arrays example
echo '<b>0-9</b>';
echo '<table width=500><tr>';
for ($i = 0; $i < count($files1); $i++) {
echo '<td>'.$files1[$i][name].'</td>';
if (($i+1) % 3 == 0)
echo '</tr><tr>';
}
echo '</tr></table>';
?>