Home > php教程 > php手册 > php计算数组相同值出现次数的代码(array_count_values)

php计算数组相同值出现次数的代码(array_count_values)

WBOY
Release: 2016-06-06 20:13:29
Original
859 people have browsed it

这篇文章主要介绍了php计算数组相同值出现次数的代码,需要的朋友可以参考下

php计算数组相同值出现次数,可以使用php自带函数array_count_values

说明

array array_count_values ( array $input )array_count_values() 返回一个数组,该数组用 input 数组中的值作为键名,,该值在 input 数组中出现的次数作为值。

array_count_values() 例子

复制代码 代码如下:


$array = array(1, "hello", 1, "world", "hello");
print_r(array_count_values ($array));
?>

以上例程会输出:

复制代码 代码如下:


Array
(
    [1] => 2
    [hello] => 2
    [world] => 1
)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template