Tech Study

PHP count() Function to get Length

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 :

(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.

$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.


Write a PHP script to get the shortest/longest string length from an array
The code returns the longest array length 7,i.e. Ferrari, and the shortest array length 3, i.e.BMW.


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().

TaggedWrite a PHP script to get the shortest/longest string length from an array

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more