Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
<?php
$stu_name = 'kira';
echo "第一种global方式<br/>";
function student_name() :string
{
global $stu_name;
return '学生名字 :' .$stu_name;
}
echo student_name().'<hr/>';
echo "第二种global['stu_name']方式<br/>";
function student_name_2():string
{
return '学生名字 :' .$GLOBALS['stu_name'];
}
echo student_name_2().'<hr/>';
echo "第三种(闭包方式)<br/>";
$stu_name_3 = function () use($stu_name):string
{
return '学生名字 :' .$stu_name;
};
echo $stu_name_3().'<hr/>';
echo "第四种(箭头函数)<br/>";
$stu_name_4 = fn() => '学生名字 :' .$stu_name;
echo $stu_name_4().'<hr/>';
echo "第五种(重点方式) 纯函数<br/>";
$stu_name_5 = function ($name):string
{
return '学生名字 :' .$name;
};
echo $stu_name_5($stu_name).'<hr/>';
echo "第一个:lcfirst首字符转换为小写:<br/>";
echo lcfirst("Kira ").'<hr/>';
echo "第二个:ucwords把字符串中每个单词的首字符转换为大写<br/>";
echo ucwords("my name is kira!").'<hr/>';
echo "第二个:ucwords把字符串中每个单词的首字符转换为大写<br/>";
echo ucwords("my name is kira!").'<hr/>';
echo "第三个:strtoupper把所有字符转换为大写<br/>";
echo strtoupper("my name is kira!").'<hr/>';
echo "第四个:substr_count来计算在字符串中出现的次数<br/>";
echo substr_count("我叫kira ,或者叫我kiraer!",'kira').'<hr/>';
echo "第五个:md5 加密方式:<br/>";
echo md5("admin1234").'<hr/>';