twerer 发表于 2015-8-31 08:46:15

PHP 统计数组元素个数

count();
sizeof();
这两个函数都返回数组元素的个数

$price =array('Tires'=>100,'Water'=>3);
$result =count($price);
$re =sizeof($price);
echo '元素个数'.$result;
echo '元素个数'.$re;

array_count_values();

该函数返回的是每个元素在数组中出现的频率
$array = array(1, "hello", 1, "world", "hello");
print_r(array_count_values($array));


页: [1]
查看完整版本: PHP 统计数组元素个数