//demo1
function sum(int $a,int $b):string{
return "$a+$b=".($a+$b);
}
echo sum(10,20);
//demo2
$email="admin@php.cn";
echo $email."<br>";
print $email;
echo "<hr>";
var_dump($email);
echo "<hr>";
var_export($email);
//demo3
$username="admin";
$userName="Peter";
echo $username."<hr>";
echo $userName."<hr>";
//demo4
$var=100;
var_dump($var);
echo "<hr>";
$var="hello";
var_dump($var);
echo "<hr>";
function ($a){
if(is_array($a)){
}else {
}
}
//demo05
$price1=99;
$price2=$price1;
echo $price1,"------",$price2,"<br>";
$price1=999;
$price2=&$price1;
$price1=9;
echo $price1,"------",$price2,"<br>";
//demo06
$var='email';
$$var='peter$php.cn';
echo $email.'<hr>';
//demo07
if(isset($username))echo $username,'<br>';
$username='peter';
echo $username,'<br>';
if(isset($username))echo $username,'<br>';
else echo '变量未定义';
//需要注意点:老师的写法:
if(isset($username)):echo $username,'<br>';
else echo: '变量未定义';
unset($username);
$email; //这样就已经声明了变量,可以使用了;
$email=null; //这个和上面作用一样;
$a=is_null($email); //判断变量是否为null;结果:$a的值是true;
$email=''; //这个值是null吗? ------------不是!这个值是空;
$a=empty($email); //用这个来判断变量是否为空;
//demo08
//数据类型:string,int,float,boolean;
//对象:
$obj=new stdClass;
$obj->email='aaa';
//echo $obj.'<br>';
$arr=['电脑','2000','huawei'];
print_r($arr);
echo '<pre>'.print_r($arr,true).'<pre>';
$num=null;//这组写法中:echo $num;却什么都不显示;
var_dump($num);
echo '<br>';
$f=fopen('0415-1.php','r');
var_dump($f);
//执行结果:resource(3) of type (stream)
if(gettype($f)==='resource'){echo '0415-1.php是一个文件';}