<?php
require_once './libs/Smarty.class.php';
// $title="你好";
$arr=array('a'=>'北京','b'=>'上海','c'=>'天津');
$arr1=array(array('哈尔滨','上海'),array('北京','天津'));
$arr2=array(array('a'=>'北京','b'=>'上海','c'=>'天津'),array('c'=>'c北京','d'=>'d上海','c'=>'天津'));
$emplist=array(array('id'=>100,'name'=>"小明","age"=>40),array("id"=>'110',"name"=>"大明","age"=>80),array("id"=>111,"name"=>"中明","age"=>60));
$smarty = new Smarty();
$smarty->assign("arr",$arr);
$smarty->assign("arr1",$arr1);
$smarty->assign("arr2",$arr2);
$smarty->assign("emplist",$emplist);
$smarty->assign("if",5);
$smarty->display("text.tpl");
?>
.tpl 页面
<br/><h1>*从from中取出数组指向temp*</h1><br/>
{foreach from=$arr item=temp key=lx}
{$lx}={$temp}
{/foreach}
<br/><h1>***取出二维数组***</h1><br/>
{foreach from=$arr1 item=temp}
{foreach from=$temp item=val}
{$val}
{/foreach}<br/>
{/foreach}
<br/><h1>***取出二维关联数组***</h1><br/>
{foreach from=$arr2 item=temp}
{foreach from=$temp item=val key=lx}
{$lx}={$val}
{/foreach}<br/>
{/foreach}
{foreach from=$emplist item=temp}
{foreach from=$temp item=val key=lx}
{if $lx!=age}
{$lx}={$val}
{/if}
{/foreach}<br/>
{/foreach}
<br/><h1>***IFELSE***</h1><br/>
{if $if>10}
a>10
{else}
a<10
{/if}
{foreach from=$emplist item=temp}
{if $temp.age<50}
小孩{$temp.name}年龄为{$temp.age}<br/>
{elseif50<$temp.age&&$temp.age<70}
青年朋友{$temp.name}年龄为{$temp.age}
{else}
老年朋友{$temp.name}年龄为{$temp.age}<br/>
{/if}
{/foreach}
// $title="你好";
$arr=array('a'=>'北京','b'=>'上海','c'=>'天津');
$arr1=array(array('哈尔滨','上海'),array('北京','天津'));
$arr2=array(array('a'=>'北京','b'=>'上海','c'=>'天津'),array('c'=>'c北京','d'=>'d上海','c'=>'天津'));
$emplist=array(array('id'=>100,'name'=>"小明","age"=>40),array("id"=>'110',"name"=>"大明","age"=>80),array("id"=>111,"name"=>"中明","age"=>60));
?>
.tpl 页面
<br/><h1>*从from中取出数组指向temp*</h1><br/>
{foreach from=$arr item=temp key=lx}
{$lx}={$temp}
{/foreach}
<br/><h1>***取出二维数组***</h1><br/>
{foreach from=$arr1
{foreach from=$temp item=val}
{/foreach}<br/>
{/foreach}
<br/><h1>***取出二维关联数组***</h1><br/>
{foreach from=$arr2
{foreach from=$temp item=val key=lx}
{/foreach}<br/>
{/foreach}
{foreach from=$emplist
{foreach from=$temp item=val key=lx}
{if $lx!=age}
{/foreach}<br/>
{/foreach}
<br/><h1>***IFELSE***</h1><br/>
{if $if>10}
{else}
{/if}
{foreach from=$emplist
{if $temp.age<50}
小孩{$temp.name}年龄为{$temp.age}<br/>
{elseif50<$temp.age&&$temp.age<70}
青年朋友{$temp.name}年龄为{$temp.age}
{else}
老年朋友{$temp.name}年龄为{$temp.age}<br/>
{/if}
{/foreach}