PHP4 User Manual: Function -> Count

zhaozj2021-02-08  295

count

(PHP 3, PHP 4> = 4.0.0) count - count the number of elements in variables

description

INT Count (Mixed Var)

Returns a variable VAR element, the most representative is an array (other types have only one element).

If this variable VAR is not an array, it will return 1 (except: count (null) is equivalent to 0).

WARNING count () may return 0 for a change in which no settings, but it can also return 0 for the initialized empty array. If you want to check if a variable is set, use the iSSet () function.

For the implementation of the array, see the array section in the manual in the use of PHP in arrays.

Example 1. COUNT ()

$ a [0] = 1;

$ a [1] = 3;

$ a [2] = 5;

$ result = count ($ a);

// $ result == 3

$ b [0] = 7;

$ b [5] = 9;

$ b [10] = 11;

$ result = count ($ b);

// $ result == 3;

Note: SIZEOF () function is count () an alias

See: sizeof (), isset (), and IS_ARRAY ().

转载请注明原文地址:https://www.9cbs.com/read-3407.html

New Post(0)