相关文章推荐
鼻子大的人字拖  ·  How to Prevent Out of ...·  2 月前    · 
闷骚的树叶  ·  How Fast is .NET ...·  2 月前    · 
另类的路灯  ·  Array.prototype.splice ...·  1 月前    · 
快乐的卤蛋  ·  Array.prototype.slice( ...·  6 天前    · 
拉风的椅子  ·  将静态openCV库与Visual ...·  1 年前    · 
细心的筷子  ·  cuda - When to use ...·  2 年前    · 
大气的木耳  ·  Can I get more ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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 ?

Its an array called $words which I am passing as you can see. I have displayed that array as a string of words separated by hyphens for reference. So that someone may find some word which the function cannot read either as a string or an integer. – SilentAssassin Jan 17, 2013 at 9:07 can you do a formatted output of your $words array as you can see below there is no error when passing your hyphenated list of words exploded into an array to the function. – Lawrence Cherone Jan 17, 2013 at 9:10 Some values in your array seems to be null and null is neither string nor integer: codepad.viper-7.com/0bniV2 – Leri Jan 17, 2013 at 11:12 @RahulYadav Forgive me, I eliminated not null values. Here's what you need: codepad.viper-7.com/RuQLGw – Leri Jan 17, 2013 at 11:59

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
                Okay this works! Is there any way to remove the null entry from the array ? And only the first and last entries of array are null. Is this happening due to some other reason or inconsistency ?
– SilentAssassin
                Jan 17, 2013 at 11:40
                it depends on your code, you haven't posted much code to see why it's behaving like this. and yes, you can delete the null valued indices of your array, take a look here and here too.
– mamdouh alramadan
                Jan 17, 2013 at 11:44
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.