Array Length in PHP: Use the Count Function with Code Examples

array length in PHP
How to Get the Length of an Array in PHP PHP provides two identical functions whenever you need to get the length of an array. The count function is the most common method. You can also use the sizeOf function as it is just an alias of the count. I prefer the count function and would recommend avoiding the sizeOf function. PHP Count Function Code Example <?php //An array with many elements. $arr = array("PHP","Javascript","Python","Java","C#","C++"); //Let's count this array using the count function and print it to console. echo "Length of \$arr is: ".count($arr); //OUTPUT //Length of $arr is: 6 ?> Counting Arrays in PHP An array is a data structure to store multiple elements. Like any programming language, PHP provides helpful functions to work with arrays. We have seen many array functions in previous articles.  One common array operation is to determine its length, which is the number of…

read more