How to calculate the average length of the strings in string array with PHP

1 Answer

0 votes
$arr = ["c#", "c", "java", "php", "python", "rust"];

$avg = strlen(implode('', $arr)) / count($arr);

echo $avg;

 
 
/*
run:
 
3.3333333333333
 
*/

 



answered Aug 20, 2024 by avibootz
...