You get duplicate rows because there are duplicate edges. I'm not the head of graph theory, but I'm sure this is not legal:
0 => array ( 0 => 'nominal', 1 => 'subtotal', ), 2 => array ( 0 => 'nominal', 1 => 'subtotal', ), ...
You can add a test to the part that creates the nodes, something like this:
if ($id==$e[0] && !in_array($e[1], $nodes[$id]['out'])) { $nodes[$id]['out'][]=$e[1]; } if ($id==$e[1] && !in_array($e[0], $nodes[$id]['in'])) // Not needed but cleaner { $nodes[$id]['in'][]=$e[0]; }
... or just make sure you don't pass duplicate edges to the function .: P
Coffee ninja
source share