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

Introduction

PHP is a server scripting language, and It is a powerful tool for making interactive and dynamic Web-pages. I have used WampServer 2.2 for following excercise..

<?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
?>

Result

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

Leave a Comment