开发者

PHP function to return the length of the longest string argument

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜