如何获取数组中最长字符串的长度 [英] How to get the length of longest string in an array

查看:27
本文介绍了如何获取数组中最长字符串的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这个数组:

$array[] = 'foo';
$array[] = 'apple';
$array[] = '1234567890;

我想得到这个数组中最长字符串的长度.在这种情况下,最长的字符串是 1234567890,长度为 10.

I want to get the length of the longest string in this array. In this case the longest string is 1234567890 and its length is 10.

这是否可以不循环遍历数组并检查每个元素?

Is this possible without looping through the array and checking each element?

推荐答案

try

$maxlen = max(array_map('strlen', $ary));

这篇关于如何获取数组中最长字符串的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆