PHP detection array length function sizeof count

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags apple array arrays example function network network programming php

php tutorials to detect array length function sizeof count
The function of the length of the array in php detection Sizeof count below to see a simple example * /
$ colorlist = array ("apple" => "red", "grass" => "green", "sky" => "blue", "night" => "black", "wall" => "white") ;

echo "The array length is:" .count ($ colorlist); // 5

/ *
count

The count () function evaluates the number of cells in the array or the number of attributes in the object.

For arrays, returns the number of its elements, 1 for all other values. If the argument is a variable and the variable is not defined, 0 is returned. If mode is set to count_recursive (or 1), the number of elements in the array in the multidimensional array is calculated recursively.

sizeof
Definition and usage
The sizeof () function evaluates the number of cells in the array or the number of attributes in the object.

grammar
sizeof (array, mode) Parameter Description
array required. Specifies the array or object to count.
mode optional. Specifies the mode of the function. Possible values:

0 - the default. Do not detect multi-dimensional arrays (arrays in arrays).
1 - Detect multidimensional arrays.
Note: This parameter is added in php 4.2.

Prompt count sizeof
Note: This function returns 0 when the variable is not set, or if the variable contains an empty array. You can use the isset () variable to test whether the variable is set.

Related Article

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.