批改状态:合格
老师批语:
浏览器接受到网站文件->传给Apache服务器,Apache服务器查看是什么文件,是HTML就解析返回给浏览器,是PHP就传给PHP模块->PHP解析完后穿给Apache服务器,Apache服务器再传到浏览器
只有文件里面有PHP代码,文件的后缀名就必须是PHP
<html><head><?phpecho '<h2 style="color:red">您好,老师</h2>';?><? echo '<h2>您好,老师</h2>'?><?= '<h2>您好,老师</h2>'?><?php $st='<h2>您好,老师</h2>'?><?=$st?></head><body></body></html>

<html><heab><?php$passed=true;echo $passed,'<hr>';echo gettype($passed),'<hr>';var_export($passed);echo '<hr>';var_dump($passed);?></heab><body></body></html>

1-2.数值类型:整数,小数
<html><heab><?php$srt=4899;$srr=4.48;var_dump($srt,$srr);?></heab><body></body></html>

1-3.字符串
<html><heab><?php$name='admin';$email='admin@qq.com';echo 'name:',$name,'<br>email:',$email;echo'<hr>';echo'hello "今天"<br>';echo'heool \'明天\'<br>';echo'c:\www\\tavv\i.html';?></heab><body></body></html>

2.复合类型
2-1.数组
<html><heab><?php$srt=[1,'牛牛','js',80];echo 'id=',$srt[0],'<br>';echo 'name:',$srt[1],'<br>';echo'kemu',$srt[2],'<br>';echo'cj',$srt[3],'<br>';//动态添加$srt[4]=true;echo'passd',$srt[4],'<br>';//追加添加$srt[]=24;echo'sj',$srt[5],'<br>';//使用追加创建数组$sss=[];$sss[]='蓝蓝的天空';$sss[]='飞老鹰';echo $sss[0],$sss[1],'<br>';$ser=['id'=>1,'name'=>'牛牛','kemu'=>'js','cj'=>80];echo 'id=',$ser['id'],'<br>';echo 'name=',$ser['name'],'<br>';echo 'kemu=',$ser['kemu'],'<br>';echo 'cj=',$ser['cj'],'<br>';//通过print_r(),显示关联数组print_r($ser);echo '<br>';echo print_r($ser,true);echo '<hr>';echo '<pre>'.print_r($ser,true).'</pre>';?></heab><body></body></html>

2.2对象
<html><heab><?php$a=1;$b=2;function sum($a,$b){return $a.'+'.$b.'='.($a+$b);}echo sum($a,$b),'<br>';//对象模版/类class Demo{private $a=1;private $b=2;public function sum(){return $this->a.'+'.$this->b.'='.($this->a+$this->b);}}$obj=new Demo();echo $obj->sum(),'<br>';?></heab><body></body></html>

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号