如何使用胡子循环?我有一个外部数字索引数组。或者如何做其他事情并保持这种结构?
我试过了:
<ul>
{{#cars}}
<li> {{#.}} {{.}} {{/.}}</li>
{{/cars}}
</ul>
> Array(
> [cars] => Array
> (
> [0] => Array
> (
> [0] => Array
> (
> [id] => 343443
> [name] => Mazda
> )
>
> [1] =>
> (
> [id] => 45353
> [name] => Toyota
> )
> )
> [1] => Array
> (
> [0] => Array
> (
> [id] => 922424
> [name] => Camry
> )
> )
> )//end cars
> )
答案 0 :(得分:4)
试试这个模板:
<ul>
{{#cars}}
{{#.}}
<li>{{id}} - {{name}}</li>
{{/.}}
{{/cars}}
</ul>
或转换数组:
array_walk( $array['cars'], function($i) use (&$cars) {
foreach( $i as $v ) $cars['cars'][] = $v;
});
,并使用这个更简单的模板:
<ul>
{{#cars}}
<li>{{id}} - {{name}}</li>
{{/cars}}
</ul>