search
Homephp教程php手册php统计数组元素个数的方法

php统计数组元素个数的方法

Jun 13, 2016 am 08:59 AM
phpnumbermainelementarrayarticlemethodofRelatedstatisticsmaterial

php统计数组元素个数的方法

   这篇文章主要介绍了php统计数组元素个数的方法的相关资料,需要的朋友可以参考下

  count():对数组中的元素个数进行统计;

  sizeof():和count()具有同样的用途,这两个函数都可以返回数组元素个数.可以得到一个常规标量变量中的元素个数,如果传递给这个函数的数组是一个空数组,或者是一个没有经过设定的变量,返回的数组元素个数就是0;

  array_count_value():统计每个特定的值在数组$array中出现过的次数;

  如:

  ?

  1

  2$array=array(4,5,1,2,3,1,2,1);

  $ac=array_count_value($array);

  将创建一个名为$ac数组,该数组包括:

  ?

  1

  2

  3

  4

  5

  6

  7

  8

  9

  10

  11关键字 值

  4 1

  5 1

  1 3

  2 2

  3 1

  发一个网友的思路,也非常不错

  ?

  1

  2

  3

  4

  5

  6

  7

  8

  9

  10

  11

  12

  13

  14$arr = array(

  '1011,1003,1008,1001,1000,1004,1012',

  '1009',

  '1011,1003,1111'

  );

  $result = array();

  foreach ($arr as $str) {

  $str_arr = explode(',', $str);

  foreach ($str_arr as $v) {

  $result[$v] = isset($result[$v]) ? $result[$v] : 0;

  $result[$v] = $result[$v] + 1;

  }

  }

  print_r($result);

  以上所述就是本文的全部内容了,希望大家能够喜欢。

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MantisBT

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.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment