A
$data = array(1000,1001,1002);
$smarty->assign('custid',$data);
{section loop=$custid name=customer}
id: {$custid[customer]}<br />
{/section}
$arr = array(1000, 1001, 1002);
$smarty->assign('myArray', $arr);
<ul>
{foreach from=$myArray item=foo}
<li>{$foo}</li>
{/foreach}
</ul>
{section}
is for looping over sequentially indexed arrays of data, unlike foreach, which is used to loop over a single associative array. Example: $data = array(1000,1001,1002);
$smarty->assign('custid',$data);
{section loop=$custid name=customer}
id: {$custid[customer]}<br />
{/section}
A {foreach}
is used to loop over an associative array as well a numerically-indexed array, unlike section, which is for looping over numerically-indexed arrays only. Example:$arr = array(1000, 1001, 1002);
$smarty->assign('myArray', $arr);
<ul>
{foreach from=$myArray item=foo}
<li>{$foo}</li>
{/foreach}
</ul>
Comments
Post a Comment