Associative arrays

PHP Smarty

Smarty - the compiling PHP template engine
Prev 来源:PHP中文社区 Next

Associative arrays

index.php:

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

index.tpl:

{$Contacts.fax}<br>
{$Contacts.email}<br>
{* you can print arrays of arrays as well *}
{$Contacts.phone.home}<br>
{$Contacts.phone.cell}<br>

OUTPUT:

555-222-9876<br>
[email protected]<br>
555-444-3333<br>
555-111-1234<br>

Prev 来源:PHP中文社区 Home Next
Variables Up Array indexes