Q:

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

belongs to collection: PHP array programs with examples

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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:

The shortest array length is 3
The longest array length is 7.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a PHP script to generate unique random numbe... >>
<< Write a PHP script which displays all the numbers ...