Php checks array length functions sizeof and count usage, sizeofcount

Source: Internet
Author: User

Php checks array length functions sizeof and count usage, sizeofcount

This example describes how to use the sizeof and count functions of php to check the array length. Share it with you for your reference. The details are as follows:

A simple example is provided below sizeof count in the php array length detection function:
Copy codeThe Code is as follows: $ colorlist = array ("apple" => "red", "grass" => "green", "sky" => "blue ", "night" => "black", "wall" => "white ");
Echo "array length:". count ($ colorlist); // 5
Count: The count () function calculates the number of units in an array or the number of attributes in an object. For an array, the number of elements is returned. For other values, 1 is returned, if the parameter is a variable but the variable is not defined, 0 is returned. If the mode is set to count_recursive (OR 1), the number of elements in the array in the multi-dimensional array is calculated recursively.

Sizeof: definition and usage. The sizeof () function calculates the number of units in the array or the number of attributes in the object.

Syntax: sizeof (array, mode)

Parameters Description
Array Required. specifies the array or object to be counted.
Mode Optional. specifies the function mode. Possible values:
0-default. Multi-dimensional arrays are not detected. arrays in the array.
1-multi-dimensional array detection.

Note: The mode parameter is added to php 4.2.
Prompt count sizeof

Note: If the variable is not set or contains an empty array, the function returns 0. You can use the isset () variable to test whether the variable is set.

I hope this article will help you with PHP programming.

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.