Blogger Information
Blog 38
fans 0
comment 0
visits 22649
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP的8种变量类型与应用场景
一个好人
Original
514 people have browsed it
  1. <?php
  2. echo 'a'; // 用于输出字符串
  3. function sum(int $a, int $b): int
  4. {
  5. return $a + $b;
  6. }
  7. echo sum(4.8, 2);
  8. echo '<pre>';
  9. $arr = ['php', 'java', 'python']; // 索引数组
  10. // 同上 $arr = array('php', 'java', 'python');
  11. var_dump($arr); //打印数组,信息全
  12. print_r($arr); // 输出数组
  13. echo '<hr>';
  14. $user = array('id' => 1, 'name' => 'hao', 'email' => 'hao@qq.com');
  15. print_r($user);
  16. $navs = ['首页', '视频教程', '学习路径', 'PHP培训新', '资源下载', '"技术文章'];
  17. $nav = '';
  18. for ($i = 0; $i < count($navs); $i++) {
  19. $nav .= "<a href='' style='padding:0 15px'>$navs[$i]</a>";
  20. }
  21. echo $nav;
  22. $navs = [['id'=>1, 'name'=>'视频教程', 'url'=>'https://www.aqy.com'], ['name'=>'学习路径', 'url'=>'https://www.aqy.com'], ['name'=>'PHP培训新', 'url'=>'https://www.aqy.com'], ['name'=>'资源下载', 'url'=>'https://www.aqy.com'], ['name'=>'技术文章', 'url'=>'https://www.aqy.com']];
  23. $nav = '';
  24. for ($i = 0; $i < count($navs); $i++) {
  25. $nav .= "<a href='{$navs[$i]['url']}' style='padding:0 15px'>{$navs[$i]['name']}</a>";
  26. }
  27. echo $nav;
  28. $nav2 = '';
  29. foreach($navs as $k=>$v){
  30. $nav2 .= "<a href='{$v['url']}' style='padding:0 15px'>{$v['name']}</a>";
  31. }
  32. echo $nav2;
  33. $nav3 = '';
  34. foreach($navs as $k=>$v){
  35. extract($v); // 从关联数组中键名为变量,值为变量的值。
  36. $nav3 .= "<a href='{$url}' style='padding:0 15px'>{$name}</a>";
  37. }
  38. echo $nav3;
  39. echo @$b; // @屏蔽错误
  40. //变量大小写敏感;函数大小写不敏感;
  41. // list() 不是函数,是一种结构
  42. list($a, $b, $c) = $arr; // 批量赋值
  43. echo $a, $b;
  44. ob_clean();
  45. ?>
  46. <!DOCTYPE html>
  47. <html lang="zh-CN">
  48. <head>
  49. <meta charset="UTF-8">
  50. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  51. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  52. <title>提交表单</title>
  53. </head>
  54. <body>
  55. <form action="test.php" method="post">
  56. <label for="uname">用户名</label>
  57. <input type="text" name="uname" id="uname"><br>
  58. <label for="pwd">密码:</label>
  59. <input type="password" name="pwd" id="pwd">
  60. <button>提交</button>
  61. </form>
  62. </body>
  63. </html>
  64. <?php
  65. class NbaPlayer{
  66. public $name;
  67. public $team;
  68. function play(){
  69. }
  70. }
  71. $james = new NbaPlayer; // 对象都需要实例化
  72. var_dump($james);
  73. ?>
  74. <script>
  75. // js对象有三种,内部对象new(内置对象);宿主对象DOM BOM; 自定义对象
  76. var d = new Date();
  77. d.getDay();
  78. // alert(d.getDay()); //星期
  79. // alert(d.getHours());
  80. // alert(navigator.appCodeName); //内核
  81. // alert(navigator.platform); //系统
  82. </script>
  83. <?php
  84. $handle = fopen('data.txt', 'r'); // 返回指针资源
  85. var_dump($handle); //resource(3) of type (stream)
  86. // $con = fread($handle,10); // 读取10个字节
  87. $con = fread($handle,filesize('data.txt'));
  88. echo $con;
  89. $pdo = new PDO('mysql:host=localhost; dbname=video', 'root', 'root');
  90. var_dump($pdo); // 对象类型object(PDO)#2 (0) { }
  91. $ch = curl_init();
  92. var_dump($ch); //resource(5) of type (curl)
  93. // null 不是0,不是false,是未定义或清空的变量,是空

总结:

根据视频内容又自己演练了一遍,没有什么难以理解的内容。

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