Php statistics on the number of array elements, php statistics on the number of arrays _ PHP Tutorial

Source: Internet
Author: User
Php calculates the number of array elements. php calculates the number of arrays. Php is used to count the number of array elements. php counts the number of arrays. count (): counts the number of elements in the array. sizeof (): has the same purpose as count, both functions can return the php method for counting the number of array elements.

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

Sizeof (): it has the same purpose as count (). both functions can return the number of array elements. we can get the number of elements in a regular scalar variable. If the array passed to this function is an empty array or an unspecified variable, the number of returned array elements is 0;

Array_count_value (): counts the number of times each specific value has exceeded in the array $ array;

For example:

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

An array named $ ac will be created, including:

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

The idea of sending a netizen is also very good.

$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);

The above is all the content of this article. I hope you will like it.

Distinct count (): counts the number of elements in the array. sizeof (): has the same purpose as count (). both functions can return numbers...

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.