Create and process tree structures in PHP