thinkphp3模板循环和打印数组
文章描述:
thinkphp3模板循环以及打印数据
控制器
public function index(){
$list = array(
array('id'=>1,'name'=>'核桃'),
array('id'=>2,'name'=>'花生')
);
$this->assign("list",$list);
$this->display();
}
视图
volist和foreach
<volist name="list" id="vo">
{$vo.id}:{$vo.name}<br/>
</volist>
<foreach name="list" item="vo" key="k" >
{$k}:{$vo.name}<br/>
</foreach>
打印
{$list|dump}
结果:
array(2) {
[0] => array(2) {
["id"] => int(1)
["name"] => string(6) "核桃"
}
[1] => array(2) {
["id"] => int(2)
["name"] => string(6) "花生"
}
}
发布时间:2021/07/02
发表评论