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()));
}
精彩评论