PHP 的 函数定义
等级 4124 次按键
定义一个带类型参数和 string 返回类型的函数,然后调用它并输出问候语。
PHP 代码
// $name 必须是字符串,$age 必须是 int;: string 声明返回类型1function greet(string $name, int $age): string { // 双引号内的变量会被替换为它们的值2 return "Hello, $name! You are $age years old.";3}4 // 输出“Hello, Alice! You are 25 years old.”5echo greet("Alice", 25);运行结果
Hello, Alice! You are 25 years old.
可以用这段代码练习打字。成绩不会计入排行榜。
这段代码中的符号
这段 PHP 代码中需要输入的符号及其出现次数。
"× 4$× 4,× 3;× 2(× 2)× 2:× 1!× 1.× 1{× 1