Home > Backend Development > PHP Tutorial > PHP method to get the length of an array or the number of occurrences of a certain value, php array_PHP tutorial

PHP method to get the length of an array or the number of occurrences of a certain value, php array_PHP tutorial

WBOY
Release: 2016-07-13 10:06:59
Original
855 people have browsed it

PHP method to get the length of an array or the number of occurrences of a certain value, php array

The example in this article describes how PHP obtains the length of an array or the number of occurrences of a certain value. Share it with everyone for your reference. The specific analysis is as follows:

count(): Count the number of elements in the array;

For example:

$arr = Array('0','1','2','3','4');
echo count($arr); // 输出 5
Copy after login

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

array_count_value() counts the number of times each specific value appears in the array $array;
For example:

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

will create an array named $ac, which includes:

Keyword Value
4 1
5 1
1 3
2 2
3 1

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/957134.htmlTechArticleHow to get the length of an array or the number of occurrences of a certain value in PHP, php array This article describes the example of PHP getting the length of an array or Method for counting the number of occurrences of a certain value. Share it with everyone for your reference. Specifically...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template