例如:
$listf[]=array('id'=>'hehe1','name'=>'guang1','type'=>array('net1','fsdf1','fdsf1'));
$listf[]=array('id'=>'hehe2','name'=>'guang2','type'=>array('net2','fsdf2','fdsf2'));
$listf[]=array('id'=>'hehe3','name'=>'guang3','type'=>array('net3','fsdf3','fdsf3'));$smarty->assign("listf","$listf");
我的想法是
<?{foreach name=outer item=contact from=$listf}?><?{$contact.id}?>
<?{$contact.name}?>
<?{foreach key=key item=item from=$contact[type]}?>//这里怎么写
这里我想输出'type'=>array('net1','fsdf1','fdsf1'));的值 可结果是乱码。<?{/foreach}?><?{/foreach}?>
$listf[]=array('id'=>'hehe1','name'=>'guang1','type'=>array('net1','fsdf1','fdsf1'));
$listf[]=array('id'=>'hehe2','name'=>'guang2','type'=>array('net2','fsdf2','fdsf2'));
$listf[]=array('id'=>'hehe3','name'=>'guang3','type'=>array('net3','fsdf3','fdsf3'));$smarty->assign("listf","$listf");
我的想法是
<?{foreach name=outer item=contact from=$listf}?><?{$contact.id}?>
<?{$contact.name}?>
<?{foreach key=key item=item from=$contact[type]}?>//这里怎么写
这里我想输出'type'=>array('net1','fsdf1','fdsf1'));的值 可结果是乱码。<?{/foreach}?><?{/foreach}?>
<!--{$id}-->
<!--{/foreach}-->
smarty 用 foreach 处理关联数组,用 section 处理下标数组
你的type数组没有下标,只能用 section 处理
<?{$alltype[no].typename}?><br />
<?{$alltype[no].typeid}?><br />
<?{section name="not" loop=$alltype[no].mintype}?>
<?{$alltype[no].mintype[not].typename}?><br />
<?{/section }?>
<?{/section }?>这是我用section写的,但是不懂用froeach写帮我写一个,可否?
<?{$contact.name}?>
<?{foreach key=key item=item from=$item.type}?>//这里怎么写
<{$item}>
<?{/foreach}?><?{/foreach}?>这样不行??
<?{$contact.name}?>
<?{foreach key=key item=item from=$item.type}?>//或者试试from=$item['type']
<?$item?>
<?{/foreach}?><?{/foreach}?>