Several ways to get array lengths in PHP

Source: Internet
Author: User
Tags array length

How PHP Gets the length of the array, using the PHP function count (), or sizeof ()

For example:

The code is as follows Copy Code

$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 elements in an array. You can get the number of elements in a regular scalar quantity, if the array passed to the function is an empty array, or a variable that is not set, the number of elements returned is 0;


As with two function functions, the manual says that sizeof () is an alias for the function count ().

So how does the multidimensional array length count?


We can refer to: http://www.111cn.net/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.