sunyke 发表于 2018-12-18 11:14:05

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 统计数组元素个数