How to count all elements in an array in PHP?To count all the elements in an array, PHP offers count() and sizeof() functions. The count() and sizeof() both functions are used to count all elements in an array and return 0 for a variable that has been initialized with an empty array. These are the built-in functions of PHP. We can use either count() or sizeof() function to count the total number of elements present in an array. For example We will discuss the program implementation for all the array elements using both count() and sizeof() methods. Example 1: Counting using count() Output Number of elements present in the array: 4 Example 2 Output Number of elements present in the array: 8 Example 3: Counting using sizeof() Output Number of elements present in the array: 6 Example 4 Output Number of elements present in the array: 7 Example 5: Example using 2D array Output 8 8
Next TopicHow to create newline in PHP
|
Javatpoint provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India