批改状态:合格
老师批语:
            
        
function 函数名称([ 参数类型限定 参数列表]) :返回值{函数体}
function GetPlayerName($name):string{return $name;}
function totalneedtopay($days, $roomprice, $discount = 0.88){$total = $roomprice * $days * $discount;return "您需要支付的总价为{$total}元。<br>";}echo totalneedtopay(2, 655);
上述代码声明了一个函数totalneedtopay,其中$days,$roomprice,$discount均为形参,其中$discount 有一个默认参数0.88,代码totalneedtopay(2, 655)中,2,655均为实参。
function add($a){return $a++;}function addex(&$a){return $a++;}$money=1;$moneyex=1;add($money);addex($moneyex);echo "{$money},{$moneyex}";
上述代码输出结果为1,2,由于add($a)函数参数为非引用参数,不会对变量本身进行修改,addex(&$a)函数参数为引用参数,传入了变量的地址,对变量本身进行修改,所以输出结果为2
function login(): string{//json_encode()第二个参数是一个常量,JSON_UNESCAPED_UNICODE(中文不转为unicode ,对应的数字 256),JSON_UNESCAPED_SLASHES (不转义反斜杠,对应的数字 64)return json_encode(['status' => 1, 'message' => '登录/成功'], 320);}
getplayername=function($id){return {$id}}
                Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号