(Most frequently..) Corrected and added note
am 17.01.2008 20:54:34 von buzon
I notice the syntaxis error in my previous message
array_slice(array_keys($hash_frequencywords,0,20)) must be
array_slice(array_keys($hash_frequencywords),0,20);
But the error continues generating me an "array enter" to my first
array. The error occurs in the following piece of code:
for ($i=0; $i
{
$str_thisword = $arr_frequencywords[$i];
echo "$i:$str_thisword ";
$hash_frequencywords[$str_thisword]++;
}
Sends me the output:
4:Array
Warning: Illegal offset type in
/home/mipyme/public_html/jpanel/index.php on line 199
5:Array
Warning: Illegal offset type in
/home/mipyme/public_html/jpanel/index.php on line 199
6:Array
Warning: Illegal offset type in
/home/mipyme/public_html/jpanel/index.php on line 199
Where it comes that extra array reference even I use elements append?
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: (Most frequently..) Corrected and added note
am 18.01.2008 00:18:51 von dmagick
buzon@alejandro.ceballos.info wrote:
> I notice the syntaxis error in my previous message
> array_slice(array_keys($hash_frequencywords,0,20)) must be
> array_slice(array_keys($hash_frequencywords),0,20);
>
> But the error continues generating me an "array enter" to my first
> array. The error occurs in the following piece of code:
>
> for ($i=0; $i
> {
> $str_thisword = $arr_frequencywords[$i];
> echo "$i:$str_thisword ";
> $hash_frequencywords[$str_thisword]++;
> }
Break it down to make sure each step does what you want.
// store in $arr_frequencyids all different words
for($i=0; $i
array_push($arr_frequencyids,explode(" ",$arr_phrase[$i]));
}
Does that do what you want and give you an array in $arr_frequencyids ?
<<<
for ($i=0; $i
>>>
You're using a different variable name here. Where does this one come from?
// Yeh i used the word 'long' twice
// so it would appear at the top of the list.
$string = "long piece of string that is really long";
$words = explode(' ', $string);
// print_r($words);
Once you get it to that stage, you can actually just use a php function
to count everything.
See http://www.php.net/manual/en/function.array-count-values.php
print_r(array_count_values($words));
If you want the top 5:
$counted_words = array_count_values($words);
$flipped_array = array_flip($counted_words);
asort($flipped_array);
print_r(array_slice($flipped_array, 0, 5, true));
You could probably do it without flipping the array (see
http://www.php.net/array_flip) but it makes sorting easier.
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php