我知道count()php 的功能,但是计算一个值出现在数组中的频率的函数是什么?
例:
$array = array(
[0] => 'Test',
[1] => 'Tutorial',
[2] => 'Video',
[3] => 'Test',
[4] => 'Test'
);
Run Code Online (Sandbox Code Playgroud)
现在我想计算"测试"出现的频率.
Wol*_*lph 15
PHP有一个函数调用array_count_values它.
例:
<?php
$array = array(1, "hello", 1, "world", "hello");
print_r(array_count_values($array));
?>
Run Code Online (Sandbox Code Playgroud)
输出:
Array
(
[1] => 2
[hello] => 2
[world] => 1
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7150 次 |
| 最近记录: |