Create complex sort functions for use in PHP's usort()