超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<array_combinearray_diff_assoc>
Last updated: Fri, 22 Jun 2007

array_count_values

(PHP 4 , PHP 5)

array_count_values -- 统计数组中所有的值出现的次数

说明

array array_count_values ( array input)

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

例子 1. array_count_values() 例子

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

以上程序输出为:

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

参见 count()array_unique()array_values()count_chars()




add a note add a note User Contributed Notes
array_count_values
tschneider at formel4 dot de
12-Jun-2002 10:09
This does not works with objects. If you have an array filled with objects, you can not count them.

Example:

<?php
$myArray = array();
for ($i = 0 ; $i < 10 ; $i++)
{
  $myObject = new MyObject();
  $myArray[$i] = $myObject;
}

echo (array_count_values($myArray));
?>

This gives you:
Warning: Can only count STRING and INTEGER values...

Found no solution for this yet...

<array_combinearray_diff_assoc>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22