Check if node has been visited
Hello, I need to check when I already visited a node when traversing through a tree. In the array of arrays that I used to create the tree I added a "visited" key to each node but when I try to update said key
$node->visited = true
the node isn't updating the value of the visited property, I don't know if this is the expected behavior and if so, is there any native way to check if the node has already been visited?
As the Readme says, the data is read-only – you can completely replace the data of the whole tree, but no nodes or nodes’ properties individually.
Which means this has to be done by the client (i.e. your code). However, maybe you don’t even need to do that, as using $tree->getNodes(), you can iterate over all nodes, so that you can be sure that your code “sees” each node exactly once when iterating.
Alternatively, if for some reason the visited property needs to be in the nodes, you can still subclass the Node class and make that possible.