我有一个字符串“34_56_67_78_97 34_56_67_78_97 23_45_56_67_89 34_56_77_88_96 45_56_66_78_88 56_67_67_78_90”但是当我运行下面的代码时,数组会返回null。从我的观点来看,与连字符相关联的数字是一个数字,我想知道字符串中出现的数字是2次或更多次。在这种情况下,答案是数字34_56_67_78_97。
$string="34_56_67_78_97 34_56_67_78_97 23_45_56_67_89 34_56_77_88_96 45_56_66_78_88 56_67_67_78_90"
$words = str_word_count($string, 1);
$frequency = array_count_values($words);
$result = array_filter($frequency, function ($x) { return $x >= 13; });
答案 0 :(得分:0)
在stackoverflow找到这个问题的链接: Numeric Values and Special charectors in str_word_count function
所以我的代码看起来应该是这样的:
$str="34_56_67_78_97 34_56_67_78_97 23_45_56_67_89 34_56_77_88_96 45_56_66_78_88 56_67_67_78_90";
$somearray = str_word_count($str, 1, '1234567890:@&_');
print_r($somearray);
打印出代码:
Array
(
[0] => 34_56_67_78_97
[1] => 34_56_67_78_97
[2] => 23_45_56_67_89
[3] => 34_56_77_88_96
[4] => 45_56_66_78_88
[5] => 56_67_67_78_90
)