I made no code corrections to the previous examples I posted.
They are just a variation of your own code examples that have been reformatted, and to which a HTML comment has been added to indicate where the missing </span>
end-tags should be.
So you could take note and correct your own code.
As I (and others) have stated, without more detailed information about your project we aren’t able to determine where else in your project the value of $visited
is being changed (to zero).