Wouldn't $ns = array_keys($tmpNS); sort($ns); be simpler solution here?