I have a two-dimensional array $persona[][]
and I want to know the number of rows it has.
I have used the function count()
, but it counts all the elements of the array, both rows and columns.
I have a two-dimensional array $persona[][]
and I want to know the number of rows it has.
I have used the function count()
, but it counts all the elements of the array, both rows and columns.
Code
Result
Explanation
Taking into account the principles of positions in the array, we understand that an array is always defined as:
Using the operator
foreach
, we can access each of the "rows" of the array. And well, it could be used to access other values, all we will do is count how many rows we get from that array. Using an increment operator.Online example!