Blogger Information
Blog 62
fans 2
comment 1
visits 42115
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP 04 Function函数(作业)(0707)
老黑
Original
632 people have browsed it
  • 实战1:
    1. function CHOICE($button){
    2. if ($button == 1)
    3. echo "你的选择太牛了";
    4. elseif ($button == 2)
    5. echo "你的选择很不错";
    6. else
    7. echo "哈哈,你赢了";
    8. };
    9. CHOICE(2);
  • 实战2:
  1. //函数声明
  2. function getReady(int $first, int $second): int{
  3. return $first * $second;
  4. }
  5. echo getReady(5,4);
  6. echo '<hr>';
  7. //可变函数
  8. $chenfa = 'getReady';
  9. echo '前面两个数相乘的结果是:' . $chenfa(58,69), '<hr>';
  10. //匿名函数
  11. $chufa = function (int $first, int $second):float {
  12. return $first/$second;
  13. };
  14. echo '第一个数除去第二个数的结果是:' . $chufa(57,7), '<hr>';
  15. //父函数
  16. $f = function(int $fisrt, $second)
  17. {
  18. $s = function(int $third) use($fisrt, $second): float
  19. {
  20. return ($first - $second) / $third;
  21. };
  22. return $s;
  23. };
  24. echo '第一个数减去第二个数,然后除以第三个数的结果是:' . $f(10, 5)(2), '<hr>';
  25. //奇怪了,最后一个出来的结果居然是-2.5,应该是2.5才对。
  26. //json多值返回
  27. function lastday(): string
  28. {
  29. $emotion = 'verybad';
  30. $world = 'nobody';
  31. return json_encode(['emotion'=>$emotion, 'world'=>$world]);
  32. }
  33. echo lastday(), '<hr>';
  34. $newday = json_decode(lastday(), true);
  35. print_r($newday);
  36. echo '<hr>';

如图:

  • 实战3:
  1. namespace ns1 {
  2. function lastday(){
  3. return '周而复始,万物长生';
  4. }
  5. }
  6. namespace {
  7. function lastday(){}
  8. echo ns1\lastday();
  9. }
Correcting teacher:GuanhuiGuanhui

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