Re: [SMARTY] Variable as array index

From: Date: Tue, 03 Dec 2002 23:09:47 +0000
Subject: Re: [SMARTY] Variable as array index
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6627@lists.php.net to get a copy of this message
On Tuesday, December 03, 2002 5:45 PM EST, Georges Berscheid <georges@berscheid.lu> wrote: > Have a look at the {foreach } template function. Thx Georges, but I actually want to use a variable as the array index, and I want to do arbirtary calculations on it: php: $people = array( array('id' => 1, 'name' => 'Duke Ionescu'), ... array('id' => 17, 'name' => 'Big Lebowsky') ); //assume we have 17 arrays in our array $sm->assign('people', $people); $columns = 4; $sm->assign('col_size', ceil(count($people)/$columns)); tpl: <table> {section name=idx loop=$people} <tr> <td> col 1: {$people[$smarty.section.idx.iteration+$col_size*1-1].name} </td> ... <td> col 4: {$people[$smarty.section.idx.iteration+$col_size*4-1].name} </td> </tr> {/section} </table> (error checking intentionally left out) Currently, I am doing this in PHP since I can't use a variable as the index of an array (let alone do calculations on it).

« previous php.smarty.general (#6627) next »