You could do something along the lines of this (I believe it's what Samuel Lopez is also suggesting in the comments):
$arr = array ('north', 'west', 'south', 'east', );
function compass_sort ($a, $b)
{
$cmptable = array_flip (array (
'north',
/* you might want to add 'northeast' here*/
'east',
/* and 'southeast' here */
'south',
'west',
));
$v1 = trim (mb_strtolower ($a));
$v2 = trim (mb_strtolower ($b));
if ( ! isset ($cmptable[$v1])
|| ! isset ($cmptable[$v2]))
{
/* error, no such direction */
}
return $cmptable[$v1] > $cmptable[$v2];
}
usort ($arr, 'compass_sort');
This assigns a number to each direction and sorts on that number, north
will be assigned zero, east
one (unless you add something in between) etc.