Iterative deepening depth-first search in arrays PHP
<p>Would it be possible to implement IDDFS algorithm in PHP with arrays in levels?</p>

<p>Supposing the following tree:</p>

<pre><code>    A
   / \
  B   C
 / \   \  
D   E   F
</code></pre>

<p>Calling <code>getNodes(A)</code> results in Array(B, C), and likewise <code>getNodes(B)</code> in Array(D, E). I already wrote getNodes function, to use it together with the BFS algorithm which unfortunately is too slow. </p>

<p>Code formatted form comment:</p>

<pre><code>function bfs($start,$target){
    $dist = 0; 

    if(empty($queue)){
        $queue = array(); 
    }; 

    if(empty($checked)){
        $checked = array();
    }; 

    array_push($queue, $start); 
    while(!empty($queue)):
        $dist = $dist + 1;
        $newqueue = array();

        foreach($queue as $node){
            if(!in_array($node,$checked)){
                array_push($checked,$node);
                $nodes=getNodes($node);
                if(checkNode($nodes,$target)){
                    return $dist;
                }else{
                    $newqueue=$nodes;
                }
            } 
            $queue = $newqueue; 
        } 
    endwhile;

    return false;
}
</code></pre>
