Difference between sizeof() and count() Methods
sizeof() Method |
count() Method |
|
1. | The sizeof() function is used to return the number of elements in an array. | The count() returns the number of elements in the array. |
2. |
Its syntax is -: sizeof(array, mode) |
Its syntax is -: count(array, mode) |
3. | Its return value is of integer type. | Its return value is of integer type. |
4. | This function is an alias of the count() function. | The count() function may return 0 for a variable that is not set. |
5. | It is supported in PHP version 4.0+ | It is supported in PHP version 4.0+ |
In conclusion, there is no difference between the count() and sizeof() methods of PHP. One method is the alias of another method. As sizeof() method execution time is longer, so count() method is considered to be better and faster.
What is the difference between count() and sizeof() functions in PHP ?
The collection objects in PHP are characterized by a length parameter to indicate the number of elements contained within it. It is necessary to estimate the length of an array in order to perform array manipulations and modifications.