php: sort and count instances of words in a given string
- by superUntitled
Hello, I need help sorting and counting instances of the words in a string.
Lets say I have a collection on words:
happy beautiful happy lines pear gin happy lines rock happy lines pear
How could I use php to count each instance of every word in the string and output it in a loop:
There are $count instances of $word
So that the above loop would output:
There are 4 instances of happy.
There are 3 instances of lines.
There are 2 instances of gin....
Thank you for your genius.