Jump to content

A couple of errors that i can't figure out...


lordphate

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.