fgswe 发表于 2015-2-13 08:48:48

PHP中使用smarty循环

smarty使用:

<?php
$items_list = array(
    23 => array('no' => 2456, 'label' => 'Salad'),
    96 => array('no' => 4889, 'label' => 'Cream')
);
$smarty->assign('items', $items_list);
?>


<ul>
{foreach from=$items key=myId item=i}
<li><a href="http://blog.163.com/lgh_2002/blog/item.php?id={$myId}">{$i.no}: {$i.label}</li>
{/foreach}
</ul>


上例将输出:

<ul>
<li><a href="http://blog.163.com/lgh_2002/blog/item.php?id=23">2456: Salad</li>
<li><a href="http://blog.163.com/lgh_2002/blog/item.php?id=96">4889: Cream</li>
</ul>
页: [1]
查看完整版本: PHP中使用smarty循环