lordphate Posted May 30, 2007 Share Posted May 30, 2007 I am getting these errors: Warning: array_count_values() [function.array-count-values]: The argument should be an array in /classes/class.autokeyword.php on line 180 Warning: Invalid argument supplied for foreach() in /classes/class.autokeyword.php on line 228 Here's the function for the first error: <?php function parse_2words() { //create an array out of the site contents $x = split(" ", $this->contents); //initilize array //$y = array(); for ($i=0; $i < count($x)-1; $i++) { //delete phrases lesser than 5 characters if( (mb_strlen(trim($x[$i])) >= $this->word2WordPhraseLengthMin ) && (mb_strlen(trim($x[$i+1])) >= $this->word2WordPhraseLengthMin) ) { $y[] = trim($x[$i])." ".trim($x[$i+1]); } } //count the 2 word phrases $y = array_count_values($y); $occur_filtered = $this->occure_filter($y, $this->phrase2WordLengthMinOccur); //sort the words from highest count to the lowest. arsort($occur_filtered); $imploded = $this->implode(", ", $occur_filtered); //release unused variables unset($y); unset($x); return $imploded; }?> And here's the second <?php function occure_filter($array_count_values, $min_occur) { $occur_filtered = array(); foreach ($array_count_values as $word => $occured) { if ($occured >= $min_occur) { $occur_filtered[$word] = $occured; } } return $occur_filtered; } ?> Any suggestions would be HIGHLY helpful! Quote Link to comment https://forums.phpfreaks.com/topic/53502-a-couple-of-errors-that-i-cant-figure-out/ Share on other sites More sharing options...
btherl Posted May 30, 2007 Share Posted May 30, 2007 The first error will probably be fixed if you initialize $y to an array (the line you commented out). It would also be less confusing if you used a different name for the count, instead of re-using $y. And $y is not a good choice of variable name It doesn't say anything about what it holds. Also, these are the two options for ($i = 0; $i < count($x) ; $i++) for ($i = 0; $i <= count($x) - 1 ; $i++) By mixing those two up (using both "<" and "- 1"), you are missing the last element of the array. Unless you intentionally do not want the last element to be processed. For the second error, $array_count_values is not an array. This is probably caused by your first error. Quote Link to comment https://forums.phpfreaks.com/topic/53502-a-couple-of-errors-that-i-cant-figure-out/#findComment-264475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.