PHP is a server scripting language whose key tool is creating dynamic and interactive Web page
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 for php array length :
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.
It returns number of elements as result.
Example to get php array length
we will now learn to get the shortest/longest string length.
$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.
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().