标签:
1,基本变量
$smarty->assign(‘data1‘,3); $smarty->assign(‘data2‘,3.45); $smarty->assign(‘data3‘,‘fffff‘); $smarty->assign(‘data41‘,true); $smarty->assign(‘data42‘,false);
整数:<{ $data1 }><br/> 小数:<{ $data2 }><br/> 字符串:<{ $data3 }><br/> 布尔型true:<{ $data41 }><br/> 布尔型false:<{ $data42 }><br/>
输出如下:
2,数组
//一维索引数组 $arr1=array("北京","上海","天津"); $smarty->assign(‘arr1‘,$arr1); //一维关联数组 $arr2 = array("city1"=>"北京", "city2"=>"上海", "city3"=>"天津"); $smarty->assign(‘arr2‘,$arr2); //二维索引数组 $arr3 = array(array("北京","上海","天津"),array("小倩","彩臣","老妖")); $smarty->assign(‘arr3‘,$arr3); //二维关联数组 $arr4 = array( array("id"=>"001","name"=>"liuhuayong","age"=>10), array("id"=>"002","name"=>"niexiaoqian","age"=>20), array("id"=>"003","name"=>"heishanlaoyao","age"=>30) ); $smarty->assign(‘arr4‘,$arr4); //二维关联数组 $arr5 = array( ‘emp1‘=>array("id"=>"001","name"=>"liuhuayong","age"=>10), ‘emp2‘=>array("id"=>"002","name"=>"niexiaoqian","age"=>20), ‘emp3‘=>array("id"=>"003","name"=>"heishanlaoyao","age"=>30) ); $smarty->assign(‘arr5‘,$arr5);
一维索引数组:<{ $arr1[0] }>||<{ $arr1[1] }>||<{ $arr1[2] }><br/> 一维关联数组:<{ $arr2.city1 }>||<{ $arr2.city2 }>||<{ $arr2.city3 }><br/> 二维索引数组:<{ $arr3[1][1] }>||<{ $arr3[1][2] }><br/> 二维关联数组:<{ $arr4[1].id }>||<{ $arr4[1].name }>||<{ $arr4[1].age }><br/> 二维关联数组:<{ $arr5.emp1.id }>||<{ $arr5.emp1.name }>||<{ $arr5.emp1.age }><br/>
输出:
3,对象
class dog{ public $name; public $age; public function __construct($name,$age){ $this->name = $name; $this->age = $age; } } $dog = new dog(‘花花‘,4); $smarty->assign(‘dog‘,$dog);
对象:<{ $dog->name }>||<{ $dog->age }>
标签:
原文地址:http://www.cnblogs.com/usa007lhy/p/4960765.html