Simple sorting and data structures in PHP