批改状态:合格
老师批语:
function add($n1, $n2 = 40, $n3){return $n1 + $n2 + $n3;}echo add(a: 66, c: 70);
function add(...$args){return array_sum($args);}echo add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
$a = 10;function add(){global $a;$b = 20;return $a + $b;}echo add();
常用函数
数组函数:
$arr = [1, 2, 3, 4, 3, 5, 2, 3, 6, 3, 5, 2];echo count($arr);echo "<pre>";print_r(array_unique($arr));print_r(array_merge($arr));echo implode(",", $arr);
$num = 16;if ($num === 16) {echo "16个";}// 或者如果只有一行输出,可以省略大括号if ($num === 16) echo "16个";//如果还有假值if ($num === 16) {echo "16个";} else {echo "你猜错了";}//如果真与假都只有一行,可以使用三元运算符来输出// 条件 ?为真的值 :为假的值echo $num === 16 ? "16个" : "你猜错了";//多条件判断if ($num >= 0 && $num < 16) {echo "数量过少";} else if ($num === 16) {echo "16个";} else if ($num > 16) {echo "数量过多";} else {echo "数值不合法";}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号