With CSS, no. You'll have to define a class, and use javascript to traverse the DOM and get the last child and apply that class to that last child.
Woops, sorry. Didn't see the PHP code after the HTML.
This does what you want; however, do note that ever level has a "last" element. But it can go for an arbitrary number of levels:
function globDir($dir)
{
$folders = glob($dir.'/*', GLOB_ONLYDIR);
if(empty($folders))
{
return '';
}
// Set up a counter
$i = 1;
// Get the max amount of folders we have
$max = count($folders);
// Start a new list for these folders
$output = '';
foreach($folders as $folder)
{
$output .= '<li';
if($i++ == $max)
{
$output .= ' class="last"';
}
$output .= '>'.basename($folder);
$path = str_replace($dir.'/', '', $folder);
$subfolders = globDir($dir.'/'.$path);
if(!empty($subfolders))
{
$output .= '<ul>'.$subfolders.'</ul>';
}
$output .= '</li>';
}
return $output;
}