PHP获取数组长度或某个值出现次数的方法,php数组
本文实例讲述了PHP获取数组长度或某个值出现次数的方法。分享给大家供大家参考。具体分析如下:
count():对数组中的元素个数进行统计;
例如:
$arr = Array('0','1','2','3','4'); echo count($arr); // 输出 5
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程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use