Php: how to get the array length _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php can be used to obtain the length of an array. The method for getting the array length in php is very simple. php provides two functions for us to calculate the length of one-dimensional arrays, such as count and sizeof, the method for getting the array length in php is very simple. php provides two functions for us to calculate the length of one-dimensional arrays, such as count and sizeof, let's take a look at several instances.

How does php obtain the length of an array? use the php function count () or sizeof ()

For example:

The code is as follows:

$ Arr = Array ('0', '1', '2', '3', '4 ');
Echo count ($ arr );

// Output 5

$ Arr = array ('A', 'B', 'C ');

Echo sizeof ($ arr );

// Output 3


Sizeof () and count () have the same purpose. 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;


The two functions are the same. in the manual, sizeof () is the alias of the function count.

How can we calculate the length of a multi-dimensional array?


Please refer to: http://www.bKjia. c0m/phper/21/32805 .htm

...

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.