Very simple, there's a function designed just for this.
check out the manual for array_count_values()

array_count_values() returns an array using the values of the input array as
keys and their frequency in input as values.

EXAMPLE:
$array = array (1, "hello", 1, "world", "hello");
print_r(array_count_values ($array));

The printout of the above program will be:

Array
(
   [1] => 2
   [hello] => 2
   [world] => 1
)

-Cheers


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
t]On Behalf Of Dore van Hoorn
Sent: Thursday, June 26, 2003 4:56 PM
To: [EMAIL PROTECTED]
Subject: [PHP] twodimensional array / word-frequencylist


Hi,

I asked the same question two days ago, but i have not received an answer
that could really help me on my way... So i'll try again, this time with
the help of a little PHP code, and soms explanations

while($myrow = mysql_fetch_row($result)) # as long as there are texts in
the database
{
        $text = $myrow[0]; # variabele text contains the text
        $array = array(); # variabele array is an empty array
        $modText = strtolower($text); #modify text: string to lower case
        $array = split(" ",$modText); #split text after empty space to create array
of words

# i would like a similar function that removes interpuntuation like "." etc.
# all i want remaining in the array are the separate words, all in lower
case

        sort($array); # sort array elements in alphabetical order
        $num = count($array); # count the number of elements in the array
        for ($c=0; $c<=$num; $c++) #as long as function has nog reached past last
element in array
        {
                $wordInText = $array[$c]; #array element is word in text
                echo "$wordInText<br>"; #print word in text
        }

# i would like a function that pushes this word into a second array.
# before pushing, it has to check whether or not the same word is already
in the array.
# if it is: do not push word into array, but add "1" to the number of
occurrences
of that word
# if it is not: push this new word into array
# all of this has to result into a word - frequency array (content analysis
of free text)
# question 1: how do i produce such an array?
# question 2: how do i get the two elements (word and number of occurrences)

# together out of the array and print them to the screen?
# f.e.: the word "computer" occurred two times in this text.

}

I do hope there is someone out there who can help me with this problem, and
help me fast....

Thnx in advance!!

Dore.
+++++++++++++++++++++++++++++++++++
N    Dore van Hoorn
S    s1000454 AlfaInformatica-RuG
E    [EMAIL PROTECTED]
W    http://www.let.rug.nl/~s1000454
+++++++++++++++++++++++++++++++++++


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.491 / Virus Database: 290 - Release Date: 6/18/2003

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.491 / Virus Database: 290 - Release Date: 6/18/2003


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to