Show first letter of a list once?
<p>I have a list of directory name and need to get the first letter from each name and just display it once before the start of that lettered group ie;</p>

<p>what I have:</p>

<p>1<br>
2<br>
3<br>
4<br>
5<br>
Aberdeen<br>
Arundel<br>
Aberyswith<br>
Bath<br>
Bristol<br>
Brighton<br>
Cardiff<br>
coventry<br></p>

<p>what I would like:</p>

<p><strong>#</strong><br>
1<br>
2<br>
3<br>
4<br>
5<br></p>

<p><strong>A</strong><br>
Aberdeen<br>
Arundel<br>
Aberyswith<br></p>

<p><strong>B</strong><br>
Bath<br>
Bristol<br>
Brighton<br></p>

<p><strong>C</strong><br>
Cardiff<br>
coventry<br></p>

<pre><code>function htmlDirList($subdirs) {
    global $z_self, $z_img_play, $z_img_lofi, $z_img_more, $z_admin,
        $z_img_down, $z_img_new, $zc;

    $now = time();
    $diff = $zc['new_time']*60*60*24;
    $num = 0;
    $dir_list_len = $zc['dir_list_len'];
    if ($zc['low']) { $dir_list_len -= 2; }
    $html = "";
    $checkbox = ($z_admin || ($zc['playlists'] &amp;&amp; $zc['session_pls']));

    /**/
    $row = 0;
    $items = sizeof($subdirs);
    $cat_cols = "2";
    $rows_in_col = ceil($items/$cat_cols);
    if ($rows_in_col &lt; $cat_cols) { $cat_cols = ceil($items/$rows_in_col); }
    $col_width = round(100 / $cat_cols);
    $html = "&lt;table width='600'&gt;&lt;tr&gt;";
    $i = 0;
    /**/
    foreach ($subdirs as $subdir =&gt; $opts) {

        if ($row == 0) {
            $class = ($cat_cols != ++$i) ? ' class="z_artistcols"' : '';
            $html .= "&lt;td $class valign='top' nowrap='nowrap' width='$col_width%'&gt;";
        }
        /*$currentleter = substr($opts, 0 , 1);
        if($lastletter != $currentleter){
        echo $currentleter;
        $lastletter = $currentleter;
        }*/

        if($alphabet != substr($opts,0,1)) {
        echo strtoupper(substr($opts,0,1)); // add your html formatting too.
        $alphabet = substr($opts,0,1);
        }


        $dir_len = $dir_list_len;
        $dir = false;
        $image = $opts['image'];
        $new_beg = $new_end = "";
        if (substr($subdir, -1) == "/") {
            $dir = true;
            $subdir = substr($subdir, 0, -1);
        }

        $path_raw = getURLencodedPath($subdir);

        $href = "&lt;a href='$path_raw";
        if (!$dir) {
            if ($zc['download'] &amp;&amp; $zc['cmp_sel']) { $html .= "$href/.lp&amp;amp;l=8&amp;amp;m=9&amp;amp;c=0'&gt;$z_img_down&lt;/a&gt; &amp;nbsp;"; }
            if ($zc['play']) { $html .= "$href&amp;amp;l=8&amp;amp;m=0'&gt;$z_img_play&lt;/a&gt; &amp;nbsp;"; }
            if ($zc['low'] &amp;&amp; ($zc['resample'] || $opts['lofi'])) { $html .= "$href&amp;amp;l=8&amp;amp;m=0&amp;amp;lf=true'&gt;$z_img_lofi&lt;/a&gt; &amp;nbsp;"; }
            if ($checkbox) { $html .= "&lt;input type='checkbox' name='mp3s[]' value='$path_raw/.lp'/&gt; &amp;nbsp;"; }
            $num++;
            if ($zc['new_highlight'] &amp;&amp; isset($opts['mtime']) &amp;&amp; ($now - $opts['mtime'] &lt; $diff)) {
                $dir_len -= 5;
                if ($z_img_new) {
                    $new_end = $z_img_new;
                } else {
                    $new_beg = $zc['new_beg'];
                    $new_end = $zc['new_end'];
                }
            }
        }
        $title = formatTitle(basename($subdir));
        if (strlen($title) &gt; $dir_len) {
            $ht = " title=\"$title.\"";
            $title = substr($title,0,$dir_len).$opts['mtime']."...";
        } else {
            $ht = "";
        }

        if ($zc['dir_list_year']) {
            $di = getDirInfo($subdir);
            if (!empty($di['year'])) $title .= " (".$di['year'].")";
        }

        $html .= "$href'$ht&gt;$new_beg$title$new_end&lt;/a&gt;&lt;br /&gt;";
        $row = ++$row % $rows_in_col;
        if ($row == 0) { $html .= "&lt;/td&gt;"; }
    }

    if ($row != 0) $html .= "&lt;/td&gt;";
    $html .= "&lt;/tr&gt;&lt;/table&gt;";
    $arr['num'] = $num;
    $arr['list'] = $html;
    return $arr;
}
</code></pre>

<p>I need help to get work.</p>
