Forum Moderators: coopster

Message Too Old, No Replies

key value count array?

creating a dynamic array that counts the occurrences of the value

         

Baruch Menachem

5:07 am on Feb 13, 2009 (gmt 0)

10+ Year Member



I want to create an array of words in a text, and then have a count of each occurrence of the word. I don't want to go to a multidimensional array, and I think I can make a 'dictionary' type array do the work.

so can I do something like check the array for a word, and if it is not in the list then add it like

$wordlist["pulchritude"]=1;

and the next time it sees the word

$wordlist["pulchritude"]++;

I also want to count characters in each key, is that possible? Or can you only get a count of the values?

Thanks

dreamcatcher

7:53 am on Feb 13, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is the array_count_values [uk.php.net] function of any use?

dc

coopster

8:27 pm on Feb 13, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Certainly looks like it fits the bill.

I also want to count characters in each key

count_chars [php.net]