Breadth-First Search Implementation in PHP