Blogger Information
Blog 14
fans 0
comment 0
visits 7553
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
传递 、打印结果、数据类型等基础知识
鹏建
Original
523 people have browsed it
  1. <?php
  2. // 同一命名空间,不能存在同名函数
  3. function sum1 (float $int,float $float):string
  4. {
  5. return "$int+$float=".($int+$float);
  6. }
  7. echo sum1(10,0.5);
  8. function sum (float $int,float $float)
  9. {
  10. echo $int+$float;
  11. }
  12. sum(10.1,0.5);
  13. ?>
  1. <?php
  2. // 打印结果
  3. $name="peter";
  4. // echo,print是PHP语言结构,并非函数
  5. // echo可以输出多个字符串
  6. echo $name.'<br>';
  7. print $name.'<br>';
  8. // echo没有返回值;print有返回值,成功的话返回1
  9. echo print $name.'<br>';
  10. echo '<br>';
  11. // 返回结构信息,类型、字节等均可知
  12. $array=[1,'张三','peter'];
  13. var_dump($array);
  14. echo '<br>';
  15. // 返回合法代码,可以直接赋值成变量
  16. var_export($array);
  17. // 变量命名
  18. // 由字母、数字、下划线组成
  19. // 不能以字母开头
  20. // 变量区分大小写
  21. // $+标识符
  22. // 要有意义
  23. $Chinese_goods;
  24. $chinese_goods;
  25. // 变量是弱类型,不用声明变量类型
  26. $nane='peter';
  27. $age=10;
  28. ?>
  1. <?php
  2. // 值传递和引用传递
  3. // 值传递
  4. $a=3;
  5. // 把3传递给$b,$a变化与$b无关
  6. $b=$a;
  7. echo $a+$b.'<br>';
  8. $a=10;
  9. echo $a+$b.'<br>';
  10. // 引用传递
  11. $a=3;
  12. // 引用传递:需要&(取地址符,又叫引用符)
  13. // 把$a传递给$b,$b随$a而变化
  14. $b=&$a;
  15. echo $a+$b.'<br>';
  16. $a=10;
  17. echo $a+$b.'<br>';
  18. // 可变变量
  19. $a='b';
  20. $b='c';
  21. $$a='c';
  22. ?>
  1. <?php
  2. // 检测变量是否存在:isset()
  3. $age=18;
  4. if(isset ($age))echo $age;
  5. // 删除变量:unset()
  6. unset($age);
  7. if(isset ($age))
  8. {echo $age;}
  9. else{echo '保密';}
  10. // 检测变量是否为null:is_null()
  11. $grade;
  12. // 返回值为true,因为变量定义但未初始化,默认为null
  13. var_dump(is_null($grade));
  14. // 检测变量是否为空:empty()
  15. $grade='';
  16. var_dump(is_null($grade));
  17. var_dump(empty($grade));
  18. ?>
  1. <?php
  2. // 数据类型
  3. // 基本类型:字符串、数值、布尔
  4. $name='peter';
  5. $age=16;
  6. // true返回1,false返回0
  7. $a=true;
  8. // 复杂类型:对象、数组
  9. class Total{
  10. public $a=3;
  11. public $b=5;
  12. public function sum($a,$b){
  13. return $a+$b;
  14. }
  15. }
  16. $total=new Total;
  17. echo $total->a;
  18. echo $total->sum(3,5);
  19. $user=['name'=>'peter','age'=>16,'sex'=>'girl'];
  20. // 特殊类型
  21. $num= null;
  22. // 资源类型
  23. $source=fopen('5.php','a+');
  24. ?>
Correcting teacher:天蓬老师天蓬老师

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!