有关 关联数组、索引数组、对象在Smarty中的应用

php文件
<?php
 $address = array('北京','天津','河北');
 $birthday = array(year=>'1990',month=>'12',day=>array('1',"星期一"));
 class Stu{
  var $name;
  var $sex;
  var $age;
  function study(){
   echo "好好学习,天天向上!";
   }
  }
$stu1 = new Stu;
$stu1->name ="张三";
$stu1->age="12";
$stu1->sex="女";
include("libs/Smarty.class.php");
$smarty= new Smarty();
$smarty->template_dir="demo/templates";
$smarty->compile_dir="demo/templates_c";
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
$smarty->assign("name","周少杰");
$smarty->assign("arr",$address);
$smarty->assign("birthday",$birthday);
$smarty->assign("student",$stu1);
$smarty->display("test.tpl");

?>
tpl文件
hello!<br />
你好!<br />
我是<{$name}>!<br />
归属地:
<select>
<option><{$arr[0]}></option>
<option><{$arr[1]}></option>
<option><{$arr[2]}></option>
</select><br>
出生年月:
<{$birthday.year}>年<{$birthday.month}>月<{$birthday.day[0]}>日<{$birthday.day[1]}><br>
我是:<{$student->name}>,<{$student->age}>岁<br />
性别:<{$student->sex}><br />
我的宣言是:<{$student->study()}><br />

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值