PHP Basics

What is the best way to calculate the size of an Array in PHP?

In some cases we may need to know the number of elements present inside an array. PHP has provided two functions that calculates the total elements present inside an array and returns the value.

Count() Function

PHP has count function which counts the array size.




echo count($fruits);


output: 3

sizeOf() function

Using sizeOf() function of PHP, we can calculate array size.




echo sizeOf($fruits);


Output: 3