We have given an array containing some array elements and the task is to count all elements of an array arr using PHP. In order to do this task, we have the following methods in PHP:
Approach 1: Using count() Method: The count() method is used to count the current elements in an array. It returns 0 for an empty array.
Count first array elements: 6 Recursive count: 8 Normal count: 2
Approach 2: Using sizeof() Method: The sizeof() method is used to count the number of elements present in an array or any other countable object.
Count second array elements: 6 Recursive count: 8 Normal count: 2
- PHP | Separate odd and even elements from array without using loop
- Reset keys of array elements using PHP ?
- How to iterate through all selected elements into an array ?
- PHP | Remove duplicate elements from Array
- How to convert list of elements in an array using jQuery ?
- Program to remove empty array elements in PHP
- How to create a string by joining the array elements using PHP ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.