Asked 7 years ago
20 Jan 2017
Views 1409
lain

lain posted

find string with max char length from array in php

suppose i have array contained strings and i want to find max length string from array of strings


 $array=array("array","php","java","eclipse","webapi");
maxString($array);


in PHP is there function which return me string which have max length in array at PHP .
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

findMaxLengthStringFromArray is can be used for the finding max length string from the array of string .



function findMaxLengthStringFromArray($array){
foreach($array as $value){
    $count[]=strlen($value);
}
arsort($count);
return array($max=$array[current(array_keys($count))],current(array_keys($count)));
}

Post Answer