PHP detection array length function sizeof and count usage _php tips

Source: Internet
Author: User
Tags array length

This article describes the PHP detection array length function sizeof and count usage. Share to everyone for your reference. Specifically as follows:

In PHP, the function that detects the length of an array has sizeof count below to see a simple example:

Copy Code code as follows:
$colorlist = Array ("Apple" => "red", "Grass" => "green", "Sky" => "Blue", "Night" => "Black" and "wall" => "white" );
echo "Array length:". Count ($colorlist); 5

The Count:count () function computes the number of cells in an array or the number of attributes in an object, returns the number of elements for an array, returns 1 for other values, and returns 0 if the argument is a variable and the variable is undefined, and if mode is set to Count_recursive (or 1), The number of elements of an array in a multidimensional array is recursively computed.

sizeof: Definition and usage, the sizeof () function calculates the number of cells in an array or the number of attributes in an object.

Syntax: sizeof (Array,mode)

Parameters Describe
Array Required, specify the array or object to count.
Mode Optionally, specify the mode of the function, the possible values:
0-Default. Multidimensional arrays are not detected, arrays in the array.
1-detects multidimensional arrays.

Note: Parameter mode is added in PHP 4.2.
Tip Count sizeof

Note: When the variable is not set, or if the variable contains an empty array, the function returns 0, and you can use the Isset () variable to test whether the variable is set.

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

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.