Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的 PHP 代码将一个数组分配给一个 Smarty 变量,该变量可以通过以下方式访问:
{$foo.123.name} {$foo.456.name} ...
数组中的123,456等索引是动态分配的(基于包含数据库的某些逻辑)。由于它们是动态分配的,因此我不能只将123等放入模板文件中。但是,这些数字在另一个 Smarty 变量中,例如:
123
456
{$bar.id}
我如何使用它$bar.id来代替123, 456?
$bar.id
对于 Smarty3:
{$foo.{$bar.id}.name}
对于 Smarty2:
{assign var="bid" value=$bar.id} {$foo.$bid.name}