How to get length of an array in php?

4 answer(s)
Answer # 1 #

Use the built-in count() function: $length = count($array); This returns the number of elements in the array.

[5 Month]
Answer # 2 #

For multidimensional arrays, count($array, COUNT_RECURSIVE) can count all elements including nested arrays.

[4 Month]
Answer # 3 #
$fruits = ["apple", "banana", "orange"];echo count($fruits); // Output: 3
[4 Month]
Answer # 4 #

Example:

[4 Month]