gpt4 book ai didi

php - 由于 array_count_values() 显示的警告消息

转载 作者:行者123 更新时间:2023-12-04 19:44:56 24 4
gpt4 key购买 nike

我正在使用 PHP 的 Codeigniter 框架并尝试从页面中提取关键字。完整代码可引用here .虽然它不是现成的。

问题是由于以下行中的数组函数造成的:

$keywordCounts = array_count_values( $words );

显示的错误信息如下:
A PHP Error was encountered

Severity: Warning

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

编辑: 的数组 $words引用 可以找到 here.

据我所知,$words 数组中没有特殊符号或无效字符。函数不读取连字符和句点,还是有其他问题?

最佳答案

你有 null数组中的值。您必须在使用 array_count_values 之前更换它们像这样:

$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);

这将导致:
array (size=4)
'ss' => int 1
'a' => int 1
4 => int 1
'' => int 1

关于php - 由于 array_count_values() 显示的警告消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14375369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com