PHP is a server scripting language whose key tool is creating dynamic and interactive Web page
Introduction
The PHP count() Function is used to count the php array length. If the function is assigned to an empty array, the function can return 0. Moreover, when a variable is not set, the function returns 0.
Syntax:
syntax for php array length :
(array_list, mode)
PHP count() Function Parameters:
$array: It is mandatory whose element will be counted
mode: It is optional from which mode of function is fixed having Possible values 0 or 1.
Return value:
It returns number of elements as result.
Example to get php array length
we will now learn to get the shortest/longest string length.
<?php
$my_array = array("bmw","jeep","dastun","ferrari","Honda");
$new_array = array_map('strlen', $my_array);
echo "The shortest array length is ". min($new_array)."<br>". // min() function " The longest array length is " . max($new_array).'.'; //max() function?>
This code creates an array called $my_array having values bmw, jeep, dastun, ferrari, and Honda. After using “array_map()” this code return with php array length of elements. This code also have min() and max() function to find longest and smallest function.
Result
The code returns the longest array length 7,i.e. Ferrari, and the shortest array length 3, i.e.BMW.
Conclusion
So from this article we learned how to find PHP array length PHP count() Function and how to find largest and shortest length array using min() and max().