[ create a new paste ] login | about

Link: http://codepad.org/0NXuKa0n    [ raw code | output | fork ]

PHP, pasted on Jul 22:
<?php


$dirs = array(
'12345',
'22345',
'32345',
'42345',
'52345',
'Aberdeen',
'Arundel',
'Aberyswith',
'Bath',
'Bristol',
'Brighton',
'Cardiff',
'coventry',
);

    $cur_let = null;
    foreach ($dirs as $dir) {
        $first_let = (is_numeric(strtoupper(substr($dir,0,1))) ? '#' : strtoupper(substr($dir,0,1)));
        if ($cur_let !== $first_let){
            $cur_let = $first_let;
            echo $cur_let."\n";
        }
            echo $dir . "\n";
    }


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#
12345
22345
32345
42345
52345
A
Aberdeen
Arundel
Aberyswith
B
Bath
Bristol
Brighton
C
Cardiff
coventry


Create a new paste based on this one


Comments: