Initialize a hash and add items to it

Author Message

Softriva .com

Saturday 02 December 2006 2:18:54 am

How can I initialize a hash and add item to it inside a loop (foreach)?

Claudia Kosny

Saturday 02 December 2006 3:02:40 am

Hi OOzy

{def $hash = hash('key1', 'value1')
     $keyArr = array('key2', 'key3', 'key4')
     $valueArr = array('value2', 'value3', 'value4')}
{foreach $keyArr as $cnt => $key}
 {set $hash = $hash|merge(hash($key, $valueArr[$cnt]))}
{/foreach}
{$hash|attribute('show')}

Does not look very efficient but it seems to be the only way.

Claudia

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.