Blogger Information
Blog 62
fans 3
comment 1
visits 29742
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php引用变量的用法与字符串函数
kiraseo_wwwkiraercom
Original
405 people have browsed it

php引用变量的用法与字符串函数

代码如下

  1. <?php
  2. $stu_name = 'kira';
  3. echo "第一种global方式<br/>";
  4. function student_name() :string
  5. {
  6. global $stu_name;
  7. return '学生名字 :' .$stu_name;
  8. }
  9. echo student_name().'<hr/>';
  10. echo "第二种global['stu_name']方式<br/>";
  11. function student_name_2():string
  12. {
  13. return '学生名字 :' .$GLOBALS['stu_name'];
  14. }
  15. echo student_name_2().'<hr/>';
  16. echo "第三种(闭包方式)<br/>";
  17. $stu_name_3 = function () use($stu_name):string
  18. {
  19. return '学生名字 :' .$stu_name;
  20. };
  21. echo $stu_name_3().'<hr/>';
  22. echo "第四种(箭头函数)<br/>";
  23. $stu_name_4 = fn() => '学生名字 :' .$stu_name;
  24. echo $stu_name_4().'<hr/>';
  25. echo "第五种(重点方式) 纯函数<br/>";
  26. $stu_name_5 = function ($name):string
  27. {
  28. return '学生名字 :' .$name;
  29. };
  30. echo $stu_name_5($stu_name).'<hr/>';
  31. echo "第一个:lcfirst首字符转换为小写:<br/>";
  32. echo lcfirst("Kira ").'<hr/>';
  33. echo "第二个:ucwords把字符串中每个单词的首字符转换为大写<br/>";
  34. echo ucwords("my name is kira!").'<hr/>';
  35. echo "第二个:ucwords把字符串中每个单词的首字符转换为大写<br/>";
  36. echo ucwords("my name is kira!").'<hr/>';
  37. echo "第三个:strtoupper把所有字符转换为大写<br/>";
  38. echo strtoupper("my name is kira!").'<hr/>';
  39. echo "第四个:substr_count来计算在字符串中出现的次数<br/>";
  40. echo substr_count("我叫kira ,或者叫我kiraer!",'kira').'<hr/>';
  41. echo "第五个:md5 加密方式:<br/>";
  42. echo md5("admin1234").'<hr/>';

效果图

1. 外部变量的5中要的五种用法

2. 字符串函数用法

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post