Q:

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

0

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

Sample arrays : ("abcd","abc","de","hjjj","g","wer")

All Answers

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

<?php
$my_array = array("abcd","abc","de","hjjj","g","wer");
$new_array = array_map('strlen', $my_array);
// Show maximum and minimum string length using max() function and min() function 
echo "The shortest array length is " . min($new_array) .
". The longest array length is " . max($new_array).'.';
?>

Sample Output:

The shortest array length is 1. The longest array length is 4.

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now