Correcting teacher:灭绝师太
Correction status:qualified
Teacher's comments:
直接打印,没有返回值。echo 能一次打印多个字符串,print 只能打印一个。echo 打印数据要比 print快。
<?php
$name = 'hanlili';
echo $name;
>>> hanlili
echo '123','x','5','=','123*5';
>>> 123x5=123*5
<?php
$school = '社会大学';
pritn &school;
>>> 社会大学
<?php
$fruits = ['苹果','西瓜','龙眼','荔枝'];
print_r($fruits);
>>>Array ( [0] => 苹果 [1] => 西瓜 [2] => 龙眼 [3] => 荔枝 )
var_dump() 不单单能打印出数据,还能打印出对应的数据类型。
<?php
$name = 'peter zhu';
var_dump($name);
>>> string(9) "peter zhu" ;
$tel = 13699789888;
var_dump($tel);
>>> int(13699789890)
<?php
$name = 'peter zhu';
$str = var_export($name,true);
//保存在线下 log.txt 文件里
file_put_contents('log.txt',$str);
php变量是根据所赋的值来决定是什么类型,如果给的是整数,那就是整型,如果给的Array,那就是Array.
<?php
//整形
$int = 1234;
var_dump($int);
>>>int(12345)
//浮点型
$float = 123.4;
var_dump($float);
>>>float(123.4)
//string
$str = 'hello word';
var_dump($str);
>>>string(10) "hello word"
//Array
$Arr = ['西红柿','辣椒','豆角'];
var_dump($Arr);
>>>array(3) { [0]=> string(9) "西红柿" [1]=> string(6) "辣椒" [2]=> string(6) "豆角" };
<?php
$a=1;
$b=$a; // 传值赋值
echo $a;
>>> 1
echo $b;
>>> 1
$a = 3; //给$a 重新赋值为3
echo $a;
>>>3;
echo $b;
>>>1;
<?php
$a=1;
$b=&$a; // 引用赋值
echo $a;
>>> 1
echo $b;
>>> 1
$a = 3; //给$a 重新赋值为3
echo $a;
>>>3;
echo $b;
>>>3;