Algorithms in PHP