Hello everybody,
I am creating an algorithm to identify the most frequently words on
different sentences, using the following code:
// store in $arr_frequencyids all different words
for($i=0; $i<count($arr_phrase); $arr_phrase)
{ array_push($arr_frequencyids,explode(" ",$arr_phrase[$i])); }
// use a hash using words as keys, and increment as frequency
for ($i=0; $i<count($arr_frequencywords); $i++)
{
$str_thisword = $arr_frequencywords[$i];
$hash_frequencywords[$str_thisword]++;
}
// descendent sort based on values
arsort($hash_frequencywords);
// store in $arr_20mostusedwords the 20 most frequent words
$arr_20mostusedwords = array_slice(array_keys($hash_frequencywords,0,20));
But... is not working. It is not counting the ocurrences. It stores as
a long string, even I used explode or trying a direct array addition
(arr1 += arr2).
Warning: Wrong parameter count for array_keys() in
/home/mipyme/public_html/jpanel/index.php on line 204
Warning: Wrong parameter count for array_slice() in
/home/mipyme/public_html/jpanel/index.php on line 204
Warning: array_slice() [function.array-slice]: The first argument
should be an array in /home/mipyme/public_html/jpanel/index.php on
line 205
Could you give me some direction? (the information comes from a DB,
but for simplifying process I asume an array instead a while DB fetch
row)
Thank you,
Alejandro
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php