in reply to Counting occurances

Your code is doing fine. Of course, you could shorten it a little bit by saying for instead of foreach.