用最少的代码写一个求3值最大值的函数
我觉得这道题不是简单在考三元运算符,主要还是在考程序员在写函数时有没有考虑到函数的可扩展性。
[code lang="php"]
$a = 1;
$b = 2;
$c = 3;
echo my_max($a, $b, $c);
function my_max()
{
$max = 0;
$args = func_get_args();
foreach ($args as $nums) {
$max = (is_numeric($nums) && $max < $nums) ? $nums : $max;
}
return $max;
}
[/code]