> Smarty模板引擎中文在线手册 > Array indexes

Array indexes

You can reference arrays by their index, much like native PHP syntax.

Example 4-3. Accessing arrays by index

index.php:

$smarty = new Smarty;
$smarty->assign('Contacts',
 array('555-222-9876',
 '[email protected]',
 array('555-444-3333',
 '555-111-1234')));
$smarty->display('index.tpl');

index.tpl:

{$Contacts[0]}<br>
{$Contacts[1]}<br>
{* you can print arrays of arrays as well *}
{$Contacts[2][0]}<br>
{$Contacts[2][1]}<br>

OUTPUT:

555-222-9876<br>
[email protected]<br>
555-444-3333<br>
555-111-1234<br>
上一篇:
下一篇: