Dijkstra's algorithm in PHP
This implementation is great and works well, but you should add an "escape door" when no path is found.

For instance, remove these two lines:

$_distArr[4][5] = 6;
...
$_distArr[6][5] = 9;


If you comment both lines, you enter an infinite loop.

To avoid this problem, I think you can add these lines right before the "calculating while" loop:



if (!array_key_exists($b, $S)) {
    echo "Found no way.";
    return;
}


Then you're set; no infinite loop!