How to use php sizeof function

藏色散人
Release: 2023-02-22 20:00:02
Original
2839 people have browsed it

php The sizeof function is used to return the number of elements in the array. The sizeof() function is an alias of the count() function. Its syntax is sizeof(array, mode). The parameter array is required and refers to the array to be counted.

How to use php sizeof function

#php How to use the sizeof function?

Definition and usage

sizeof() function returns the number of elements in the array.

The sizeof() function is an alias of the count() function.

Syntax

sizeof(array,mode);
Copy after login

Parameters

array Required. Specifies the array to count.

mode Optional. Specifies the mode of the function. Possible values:

0 - Default. Not counting all elements in a multidimensional array.

1 - Recursively count the number of elements in an array (count all elements in a multidimensional array).

Return value: Returns the number of elements in the array.

PHP Version: 4

Example 1

Recursively count the number of elements in an array:

array ( "XC60", "XC90" ), "BMW"=>array ( "X3", "X5" ), "Toyota"=>array ( "Highlander" ) ); echo "Normal count: " . sizeof($cars)."
"; echo "Recursive count: " . sizeof($cars,1); ?>
Copy after login

Output:

Normal count: 3 Recursive count: 8
Copy after login

Example 2

Return the number of elements in the array:

Copy after login

Output:

3
Copy after login

The above is the detailed content of How to use php sizeof function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!