abstract:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>smarty</title&
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>smarty</title> </head> <body> <{* 模板中定义变量 *}> <{assign var = "name" value = "PHP"}> <p><{$name}></p> <{* 模板中定义变量:变量简写 *}> <{$name = "PHP中文网"}> <p><{$name}></p> <{* IF语句 *}> <{$data = 21}> <{if $data is odd}> <p><{$data}>是奇数</p> <{else}> <p><{$data}>是偶数</p> <{/if}> <{$grade = 70}> <{if $grade >= 80}> <p>成绩优秀!</p> <{elseif $grade >=60}> <p>成绩良好!</p> <{else}> <p>成绩不及格,赶紧补考吧!</p> <{/if}> <{* FOR循环语句 *}> <{for $i = 0 to 10 step 2}> <{$i}>, <{forelse}> <p>循环条件错误!</p> <{/for}> <p></p> <{* WHILE循环语句 *}> <{$i = 0}> <{while $i < 10}> <{$i++}>, <{/while}> <p></p> <{* FOREACH遍历一维数组 *}> <{$people = ['name'=>'小明','sex'=>'男','age'=>35]}> <{* $people = [] *}> <{foreach $people as $key => $value}> <{$key}> => <{$value}> <br> <{foreachelse}> <p>没有数据</p> <{/foreach}> <{* FOREACH遍历二维数组 *}> <{$people = [ ['name'=>'小明','sex'=>'男','age'=>35], ['name'=>'小花','sex'=>'女','age'=>25], ['name'=>'小北','sex'=>'男','age'=>55] ]}> <{* $people = [] *}> <{foreach $people as $value}> <p>姓名:<{$value.name}>,性别:<{$value.sex}>,年龄:<{$value.age}></p> <{foreachelse}> <p>没有数据</p> <{/foreach}> <{* 模板中定义函数,简写函数 *}> <{function name = "welcome" country = "中国"}> <p>欢迎来<{$country}></p> <{/function}> <{call name = "welcome"}> <{call name = "welcome" country = "意大利"}> <{function country}> <p>国籍:<{$country}></p> <{/function}> <{country country = "澳大利亚"}> </body> </html>
Correcting teacher:查无此人Correction time:2019-09-05 14:30:01
Teacher's summary:完成的不错。写代码时,要注意php和html代码不要搞混。特别是符号。继续加油