How to count all array elements in PHP ?
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