Re: [SMARTY] indexing arrays in smarty

From: Date: Mon, 21 Feb 2005 18:49:59 +0000
Subject: Re: [SMARTY] indexing arrays in smarty
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12253@lists.php.net to get a copy of this message
Atte André Jensen wrote:
I'm trying to use indexes in smarty, but can't make it work... I have the following tow arrays: $cats = array(
          array('name' => 'hans', 'favorite_food_id' => '1'),
          array('name' => 'john', 'favorite_food_id' => '2'));
$food = array('1' => array('id' => '1', 'food_name' => 'water'),
          '2' => array('id' => '2', 'food_name' => 'bread'));
In my opinion its the task of the Application, to join the array, instead of delivering two seperate arrays. But if you like you can of course do it as follows {foreach from=$cats item=item} <p>{$item.name} loves {$food[$item.favorite_food_id].food_name} {/foreach} Nevertheless you should consider to let the business logic do the job, instead of the display. hth Andre

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