<?php
// 示例数组
$array = array(1, "hello", 1, "world", "hello", 1);
// 使用 array_count_values 函数统计数组中每个值出现的次数
$result = array_count_values($array);
// 输出结果
print_r($result);
?>
/*
解释说明:
array_count_values 函数用于统计数组中所有值出现的次数。它返回一个数组,其中键是原数组中的值,值是该值出现的次数。
在上面的例子中:
- 数字 1 出现了 3 次
- 字符串 "hello" 出现了 2 次
- 字符串 "world" 出现了 1 次
所以输出的结果将是:
Array
(
[1] => 3
[hello] => 2
[world] => 1
)
*/
上一篇:php mongodb
下一篇:php dechex
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站