The PHP Function Sizeof
An array is a data structure that stores information in a certain order. An array can hold a variety of data types such as integers, strings, and objects. When dealing with an array, you will often want to know its length in order to perform various operations on it. This is where the php function sizeof comes in.
sizeof() is a built-in function in PHP that is an alias of the count() function. Both functions work similarly and have the same purpose. Count() is used to count all of the elements or properties in an array or other countable object, including multidimensional arrays.
The sizeof() function works by taking in two parameters: the array that you wish to count, and an optional mode that determines how the function will behave. The mode can be either COUNT_NORMAL, which is the default, or COUNT_RECURSIVE. If you use the COUNT_RECURSIVE mode, then the function will recursively count all of the elements in the array and any sub-arrays that are contained within it.
Despite being an alias of count(), sizeof() takes significantly longer to execute than count(). For this reason, I recommend that you always use count() to count the number of items in your arrays, unless there is a compelling reason to do otherwise. Also, if you have the ability to, try to avoid using sizeof() in loops, as it will cause your code to run slower and consume more resources. Instead, prefer the powerful forEach() function to iterate over arrays if possible.