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.
Answer # 2 #
For multidimensional arrays, count($array, COUNT_RECURSIVE) can count all elements including nested arrays.
Answer # 3 #
$fruits = ["apple", "banana", "orange"];echo count($fruits); // Output: 3