php统计数组不同元素的个数的实例方法
作者:(*-*)浩 时间:2023-06-11 23:04:59
php统计数组元素个数
count():对数组中的元素个数进行统计;
sizeof():和count()具有同样的用途,这两个函数都可以返回数组元素个数。可以得到一个常规标量变量中的元素个数,如果传递给这个函数的数组是一个空数组,或者是一个没有经过设定的变量,返回的数组元素个数就是0;
array_count_value():统计每个特定的值在数组$array中出现过的次数
如:
$array=array(4,5,1,2,3,1,2,1);
$ac=array_count_value($array);
将创建一个名为$ac数组,该数组包括:
关键字 值
4 1
5 1
1 3
2 2
3 1
例如:
<?php
$a=array("Cat","Dog","Horse","Dog");
print_r(array_count_values($a));
?>
输出:
Array ( [Cat] => 1 [Dog] => 2 [Horse] => 1 )
以上方法很简单,大家可以测试学习下。
标签:php,统计数组
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
关于PyQt5中QtGui.QImage图片显示问题解析
2022-05-17 19:59:12
![](https://img.aspxhome.com/file/2023/4/111884_0s.png)
PHP中生成UUID自定义函数分享
2023-11-14 16:57:04
golang的HTTP基本认证机制实例详解
2024-04-26 17:28:39
MySQL中使用FREDATED引擎实现跨数据库服务器、跨实例访问
2024-01-25 12:55:52
![](https://img.aspxhome.com/file/2023/3/74853_0s.png)
Django1.9 加载通过ImageField上传的图片方法
2022-11-17 10:07:12
关于Python的一些学习总结
2022-01-10 11:23:41
pyqt添加启动等待界面的操作
2023-04-29 02:27:11
工作需要写的一个js拖拽组件
2024-04-08 10:53:20
Mysql systemctl start mysqld报错的问题解决
2024-01-26 03:41:45
![](https://img.aspxhome.com/file/2023/3/103573_0s.jpg)
python 读取.csv文件数据到数组(矩阵)的实例讲解
2023-08-10 12:12:36
详解Python Qt的窗体开发的基本操作
2021-03-28 00:58:12
![](https://img.aspxhome.com/file/2023/7/135447_0s.png)
MySQL复制表结构和内容到另一张表中的SQL语句
2024-01-20 17:20:59
一个可应用在ASP 标记加密文件的MD5的DLL组件
2008-04-12 07:21:00
python自动化测试无法启动谷歌浏览器问题
2021-01-08 21:35:54
![](https://img.aspxhome.com/file/2023/8/117948_0s.png)
python 划分数据集为训练集和测试集的方法
2023-01-10 12:18:36
Python 3.6 中使用pdfminer解析pdf文件的实现
2023-09-02 08:34:08
![](https://img.aspxhome.com/file/2023/3/92183_0s.png)
PHP实现的杨辉三角求解算法分析
2023-11-19 13:52:29
![](https://img.aspxhome.com/file/2023/9/55679_0s.jpg)
python在html中插入简单的代码并加上时间戳的方法
2022-06-19 05:33:01
![](https://img.aspxhome.com/file/2023/7/103367_0s.jpg)
Python函数参数类型*、**的区别
2022-03-01 18:09:54
高效管理http连接的方法
2022-02-16 23:12:14
![](https://img.aspxhome.com/file/2023/5/132505_0s.png)