Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning message displayed due to array_count_values()

I am using Codeigniter framework of PHP and trying to extract keywords from the page. The complete code for reference can be seen here. It is not ready-made though.

The issue is due to the array function in the following line:

$keywordCounts = array_count_values( $words );

The error message being displayed is as follows:

A PHP Error was encountered

Severity: Warning

Message: array_count_values() [function.array-count-values]: Can only count STRING and INTEGER values!

EDITED: The array $words for reference can be found here.

There are no special symbols or invalid characters to my knowledge in the $words array. Hyphens and periods are not read by the function or is there some other issue ?

like image 477
SilentAssassin Avatar asked Oct 28 '25 01:10

SilentAssassin


1 Answers

you have null values in your array. you have to replace them before working with array_count_values like this:

$x = array('s'=>'ss', 'a',4 , 'sss' => null);

$ar = array_replace($x,array_fill_keys(array_keys($x, null),''));

$v = array_count_values($ar);

var_dump($v);

which will result:

array (size=4)
  'ss' => int 1
  'a' => int 1
  4 => int 1
  '' => int 1
like image 118
mamdouh alramadan Avatar answered Oct 29 '25 17:10

mamdouh alramadan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!