Jump to content

Recommended Posts

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!

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.