Searching string for entries and tabling those entries

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dink87522
Forum Newbie
Posts: 7
Joined: Mon Dec 28, 2009 10:19 pm

Searching string for entries and tabling those entries

Post by dink87522 »

I have a string that looks like "14, 1, 4, 5, 16, 17, 2, 2, 5, 1, 5, 20, 5" etc but with many more characters (and it may end up with a few thousand characters to it in the end). Each character is between 1 and 20 (inclusive) and separated by ",".

I need to search this string and count how many times each number occurs (i.e how many 1's, how many 2's ... how many 20's). I sort of got it working using a for loop and switch statement although it was rather obfuscated.

What would be the easiest way to do this?
dink87522
Forum Newbie
Posts: 7
Joined: Mon Dec 28, 2009 10:19 pm

Re: Searching string for entries and tabling those entries

Post by dink87522 »

Nevermind, I found a workaround.
Post Reply