跟老师那样是运行错误?
这个函数没有返回值怎么会得出结果哦,而且第24行的foeach循环不应该这样写吗 foreach ($nums as $num) {
这个函数没有返回值怎么会得出结果哦,而且第24行的foeach循环不应该这样写吗 foreach ($nums as $num) {
2017-07-17
老师的代码:
function get_max_value($nums) {
$max_vlaue = $nums[0];
foreach ($arr_num2 as $num) {
if ($max_vlaue < $num) {
$max_vlaue = $num;
}
}
return $max_vlaue;
}
$arr_num = array(23, 4, 2, 34, 32);
echo get_max_value($arr_num);
我运行错误,后面自己改了一下,把foeach里的($arr_num2 as $num)改成($nums as $num)才可以
function get_max_value($nums) {
$max_vlaue = $nums[0];
foreach ($nums as $num) {
if ($max_vlaue < $num) {
$max_vlaue = $num;
}
}
return $max_vlaue;
}
$arr_num = array(23, 4, 2, 34, 32);
echo get_max_value($arr_num);
举报