Get unique entries from array
I think the associative array approach is good. You could probably get away with:

for ($i = 0; $i &lt; count($nodes); $i++)
  for ($j = 0; $j &lt; count($nodes[$i]); $j++)
    $uniekenodes[$nodes[$i][$j]]++;


As incrementing NULL values results in 1.