简体   繁体   English

如何在整个数组上运行 php strlen 函数?

[英]How to run php strlen function on entire array?

Why do I want to sum the text in an array in PHP but the strlen function can only be executed according to the order of my array.为什么我想在PHP中对数组中的文本进行求和,但是strlen函数只能按照我数组的顺序执行。 Eg:例如:

$array = ['One', 'Two', 'Three'];

strlen result is严格的结果是

3 3 5

What i want is 11 .我想要的是11 Is there any solution?有什么解决办法吗?

try this试试这个

$array = ['One', 'Two', 'Three'];
echo $total_str_length = array_sum(array_map('strlen', $array));

O/P: 11开/销: 11

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM