Blogger Information
Blog 19
fans 0
comment 0
visits 9838
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php中变量与函数的声明及使用
newbie
Original
404 people have browsed it

演示图片

代码

  1. <?php
  2. //变量的声明
  3. $php = "博客后台";
  4. //函数的声明
  5. function getPHP(string $php): string
  6. {
  7. return "欢迎进入" . $php;
  8. }
  9. //调用函数
  10. echo getPHP("许小可博客");
  11. echo "<hr>";
  12. //查看变量详细信息
  13. var_dump($php);
  14. echo "<hr>";
  15. //参数不足和js一样用默认参数
  16. function getNum(float $asa, float $sds = 2): float
  17. {
  18. return $asa * $sds;
  19. }
  20. echo getNum(6);
  21. //参数过多时用...rest
  22. $num = function (...$args) {
  23. return array_reduce($args, function ($nums, $tos) {
  24. return $nums + $tos;
  25. }, 0);
  26. };
  27. echo "<hr>";
  28. echo $num(5, 6, 7, 8, 9);
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