开发者

PHP function to return the length of the longest string argument

开发者 https://www.devze.com 2022-12-21 07:34 出处:网络
Eg: GetLogestString(\"bae\",\"afaaa\",\"aaa\") should return 5 GetLogest开发者_C百科String(\"baeedfefe\",\"afaaaa\",\"aaa\",\"bb\") should return 9Use array_map(), strlen(), max() and func_get_args

Eg:

GetLogestString("bae","afaaa","aaa") should return 5

GetLogest开发者_C百科String("baeedfefe","afaaaa","aaa","bb") should return 9


Use array_map(), strlen(), max() and func_get_args():

function getLongestString() {
  $args = func_get_args();
  return max(array_map('strlen', $args));
}

Edit: In PHP 5.2 you have to store the result of func_get_args() in a temporary variable. In PHP 5.3 you can do this:

function getLongestString() {
  return max(array_map('strlen', func_get_args()));
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号