How PHP gets the length of an array or the number of times a value occurs

Source: Internet
Author: User

This article mainly introduces PHP to get the length of the array or a number of occurrences of the method, example analysis of the count () and Array_count_value () the use of skills, the need for friends can refer to the

This example describes how PHP gets the length of an array or how many times a value appears. Share to everyone for your reference. The specific analysis is as follows:

COUNT (): counts the number of elements in an array;

For example:

1 2 $arr = Array (' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 '); echo count ($arr); Output 5

sizeof () and count () have the same purpose, both functions can return the number of elements in an array. You can get the number of elements in a regular scalar quantity, if the array passed to the function is an empty array, or a variable that is not set, the number of elements returned is 0;

Array_count_value () counts the number of occurrences of each particular value in the array $array;
For example:

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

An array named $ac is created, which includes:

Keyword value
4 1
5 1
1 3
2 2
3 1

I hope this article will help you with your PHP program design.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.